body:
I have some basic programming experience but I am a novice at both C and Arduino.

I messed around with the example LCD code to try to move a character around with the onboard keypad. I also wanted the actual move to occur only once the button is released, like you would expect from a keypad.

The code works, but I have a feeling all the empty WHILE loops inside the main loop() function I used are not the best practice.. :)

How did I do? Is there a more convenient/elegant solution I missed and can learn from?

Thanks, and sorry for the messy code!

    void loop()
    {
      lcd.clear();
      lcd.setCursor(posCol,posRow);      //initialized beforehand
      lcd.print("O");                    //random char to move
      lcdOld = btnNONE;

      while (read_LCD_buttons() == btnNONE)     //do nothing while nothing is pressed
      {
      }

      lcdOld = read_LCD_buttons();

      while (read_LCD_buttons() == lcdOld)     //do nothing while button is down
      {
      }

      switch (lcdOld)               // depending on which button was pushed, we perform an action
       {
       case btnRIGHT:
         {
         posCol++;
         break;
         }
       case btnLEFT:
         {
         posCol--;
         break;
         }
       case btnUP:
         {
         if (posRow == 1)
         {
            posRow = 0;
            break;
         }
         else
         {
         break;
         }
         }
       case btnDOWN:
         {
         if (posRow == 0)
         {
            posRow = 1;
            break;
         }
         else
         {
         break;
         }
         }
       case btnSELECT:
         {
         break;
         }
         case btnNONE:
         {
         break;
         }
     }
    }

title: Moving a character around an LCD screen - is there a better way?

Answers: 1

body:
You could encapsulate the logic of detecting a button release into its
own function:

<!-- language: lang-c++ -->

    // Return the button that was just released, or btnNONE.
    int releasedButton()
    {
        static int last_button = btnNONE;
        int previous_button = last_button;
        last_button = read_LCD_buttons();
        if (last_button == btnNONE)
            return previous_button;
        else
            return btnNONE;
    }

Then the logic in the loo gets simplified:

    void loop()
    {
        switch (releasedButton()) {
            ...
        }
    }


body:
Apologies for the title gore and whether this seems to be a fairly basic question, I'm an Arduino noob.

I'm working on a wearable sensor system project at my university using an Arduino UNO R3 to handle all the sensors and power them. I'm currently powering the board with a USB connection and will be powering my components from the board's 5V pin as they can all safely operate with that voltage. The individual components do not exceed their I/O pins max current and their combined current usage doesn't exceed the boards maximum current.

My question comes in here: in the past if I've needed to connect multiple components to the ground and 5V pins of an Arduino board, I was always taught to use a matrix board to solder my component's 5V and GND wires to, where they could then be powered from two soldered wires from the microcontrollers 5V and GND pins.

Given that this is a wearable system, I would like to minimise any unnecessary hardware and so proposed to my supervisor that we cut out the matrix board and simply solder the VCC wires of the components together to one header pin which we can then plug into the 5V pin on the board to draw power. He strongly cautioned against this but wasn't able to provide a concrete reason as to why it would be a problem; as far as I can see the fundamental theory is the same and we are simply cutting out an unnecessary middle man.

Is there something I'm missing here or does this solution seem like it would work fine? Additionally, if this solution works for VCC, would the same principle work for sharing a grounded connection?

title: Connecting multiple component's VCC wires to one Arduino UNO R3 5V Pin

Answers: 1

body:
Assuming you have suitable soldering skill, there are some considerations when you solder lots of wires to one header:

 - Lots of wires means lots of weight. The strain of several wires may degrade your connection or header over time, especially for a wearable system, where I assume the parts would be subject to some movement.
 - The width of the connection when all the wires are soldered to it. It might touch adjacent pins, or lean on them, creating mechanical stress. Heatshrink or sleeving can help with the electrical contact issue, but won't remove the mechanical risk.
 - Lots of wires soldered to one point may make the system more difficult to service. Instead of desoldering the wire to one component, you have to either desolder them all, or cut the wire to the one suspect component and then solder together wire stubs later to replace it.

When referring specifically to power supply pins, you'll need to consider the peak current requirements of anything you power from it. Based on https://playground.arduino.cc/Main/ArduinoPinCurrentLimitations it seems like you shouldn't be pulling more than 200mA from the Vcc PIN. Check the *maximum* current draw of all of your components that you want to power, add them together, and make sure it's under the limit of the Arduino board.


body:
I brought 860mhz-960mhz UHF rfid reader module for chip card skimmer from follow link:

https://www.alibaba.com/product-detail/860mhz-960mhz-UHF-rfid-reader-module_60312310172.html

I want to do communication with arduino uno so is it possible to connect
[![enter image description here][1]][1]

VCC to VCC
GND to GND
RX to TX
TX to RX

and what is meaning of EN and GPIO if any one know please help me to do serial communication.

  [1]: https://i.stack.imgur.com/usDdL.jpg

title: How to connect RFID Module to Arduino UNO

Answers: 1

body: Its just a simple RFID module based on UART working on 5V.  EN stands for enable, to enable the chip. It has to be connected to VCC too. Because its active high signal. GPIOs are general purpose io pins. No need of them if you are just reading from RFID.


body:
Arduinites!

Hoping you can help a newbie. I'm putting together a board for a Christmas present this year. It's replacing the factory board that comes on a beer fridge/vending machine, with minimal interactions.

Basically, when the beer can falls into an outlet chute, it trips a switch that triggers some LEDs and audio. Pretty simple stuff. The fridge supplied +5v to the previous board, so I thought I could remove it and simply swap in the Arduino.

The code runs fine when the Arduino is powered by USB/laptop. I spliced a USB header onto the +5v wire supplied by the fridge and plugged it all in. Now, it will boot up, play some weird fuzz out of the speaker, and reset after about 10 seconds.

How can I use the +5v to power my nutty creation? The previous board had a capacitor on it which I removed (I know next to nothing about some of this stuff but it seems like maybe that would help?)

Here's a photo of what I'm working with. If I need to provide any additional information or photos I can do that.

[![My board][1]][1]

[![Fridge Schematic][2]][2]

[![Power][3]][3]

[![enter image description here][4]][4]
If you have any advice, please ELI5 with regards to what I might be able to place in my circuit to get this working (links or definitions are incredibly helpful!)

Any help is appreciated!

  [1]: https://i.stack.imgur.com/WxWCb.jpg
  [2]: https://i.stack.imgur.com/hJTqZ.jpg
  [3]: https://i.stack.imgur.com/b6EnD.jpg
  [4]: https://i.stack.imgur.com/i3D2D.jpg

title: Arduino Uno Keeps Resetting (Power issue)

Answers: 1

body:
How much current takes your board with all components? Maybe the 5V power supply can not give you the wanted current.

- You can use a oscilloscope to see what is happening with the 5V when you use your board (maybe not enough current) for example interruptions on your connection or the voltage is not stable.
- Maybe you can find a datasheed for the power supply for more information
- try your board with another power supply to see if this is a problem of the board or the power supply

I just recognized in the third picture that the transformers output have 5V and 200mA. Your speaker will maybe have 8 Ohm (please write us the resistance). This means it will take 5V/8 Ohm this equals a current of 0,625 or 625mA. This current is 3 times higher than the output current of the transformer.

My theory 1 is:

Your circuit worked on your computers USB because you have got usb 3.0 and the max current for it is 900mA wich is much greater than 625mA and enough for leds, speaker and arduino. Your speaker is not connected directly to a pin and gnd. Some seperate electronics manages the pulses and takes directly the 5V of the USB.

My theory 2 is:
You used USB 2.0 (500mA) or USB 3.0 (900mA) and the speaker is connected directly to a pin (the resistance is ok or you added some resistance). The sound was probably not loud because the power was low. The current for both USBs were enough for leds, speaker and arduino.

Now to your problem with the resetting.

The solution:

Switch off the speaker and test your circuit without it. (I think it will work fine).

If it works: You took too much current and this current heated the pin and  influenced the charecteristics of the pin and finally the voltage at your pin (weird fuzz). Add a variable resistor in series to your speaker an try it.

If it not works: Measure the output voltage of the transformer and wirte us the value.


body:
I am trying to understand in details the (great tutorial and) code of Nick Gammon **''Improved sketch using Timer 1''**, available here: http://www.gammon.com.au/forum/?id=12075 . I post the whole code at the end of this in the case the web page would go down.

I find the code quite clear: Nick wants to estimate the value of a capacitor by measuring its characteristic discharge time. For this he uses one of the Arduino timers, together with an interrupt raised by the analog comparator. As the Arduino timer he uses is only 16 bits and he uses a pre-factor of 1 at 16MHz, he expects overflow of the timer to occur so he keeps track of the number of overflows that happened:

    ISR (TIMER1_OVF_vect)
    {
      ++overflowCount;               // count number of Counter1 overflows
    }  // end of TIMER1_OVF_vect

However, what I do not understand is why he tries to find a 'missed overflow' in the ISR raised by the analog comparator (this is in the ```ISR (ANALOG_COMP_vect)``` function body):

    // if just missed an overflow
        if ((TIFR1 & bit (TOV1)) && timer1CounterValue < 256)
          overflowCopy++;

So my questions are:

- How could a missed overflow happen? 'Naively' I would guess that, as soon as the analog comparator ISR is called, the timer stops incrementing so that it should not overflow after the comparator ISR fires, am I wrong?

- If there is a timer overflow happening, I understand why one wants to check TIFR1 at TOV1 (this is the overflow flag, set automatically at timer overflow, which should be cleared as a side-effect of execution of ```ISR(TIMER1_0VF_vect)``` according to datasheet), why add also the ```&& timer1CounterValue < 256``` in the if condition? I understand that ```256``` is a 'small' value, any reason for this exact numerical value?

# Copy of the whole code:

    /*
    Capacitance meter

    Author: Nick Gammon
    Date:   27 June 2013

    Pulse pin (D2): Connect to capacitor via 10K resistor.

    Reference voltage of 0.632 of output pin (pulsePin) connected to D7.
    In my case I used 3.06V because I measured 4.84 on the 5V pin.

    Measure pin (D6) connected to first leg of capacitor, other leg connected to Gnd.

    Like this:

    Capacitor to test:

    D2  ----> 10K ----> D6 ----> capacitor_under_test ----> Gnd

    Reference voltage:

    +5V ----> 1.8K ---> D7 ---> 3.1K ----> Gnd

    */

    const byte pulsePin = 2;
    const float resistance = 10000.0;

    volatile boolean triggered;
    volatile boolean active;

    volatile unsigned long timerCounts;
    volatile unsigned long overflowCount;

    ISR (TIMER1_OVF_vect)
    {
      ++overflowCount;               // count number of Counter1 overflows
    }  // end of TIMER1_OVF_vect

    ISR (ANALOG_COMP_vect)
      {
      // grab counter value before it changes any more
      unsigned int timer1CounterValue;
      timer1CounterValue = TCNT1;  // see datasheet, page 117 (accessing 16-bit registers)
      unsigned long overflowCopy = overflowCount;

      if (active)
        {
        // if just missed an overflow
        if ((TIFR1 & bit (TOV1)) && timer1CounterValue < 256)
          overflowCopy++;
        // calculate total count
        timerCounts = (overflowCopy << 16) + timer1CounterValue;  // each overflow is 65536 more
        triggered = true;
        digitalWrite (pulsePin, LOW);  // start discharging capacitor
        }
      }  // end of ANALOG_COMP_vect

    void setup ()
      {
      pinMode (pulsePin, OUTPUT);
      digitalWrite (pulsePin, LOW);

      Serial.begin (115200);
      Serial.println ("Started.");
      ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
      ACSR =  bit (ACI)     // (Clear) Analog Comparator Interrupt Flag
            | bit (ACIE)    // Analog Comparator Interrupt Enable
            | bit (ACIS0) | bit (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on rising edge)
       }  // end of setup

    void startTiming ()
      {
      active = true;
      triggered = false;

      // prepare timer
      overflowCount = 0;            // no overflows yet
      // reset Timer 1
      TCCR1A = 0;
      TCCR1B = 0;
      TCNT1 = 0;      // Counter to zero
      TIFR1 = bit (TOV1);  // clear overflow bit
      // Timer 1 - counts clock pulses
      TIMSK1 = bit (TOIE1);   // interrupt on Timer 1 overflow

      // get on with it
      digitalWrite (pulsePin, HIGH);  // start charging capacitor
      // start Timer 1, no prescaler
      TCCR1B =  bit (CS10);

      } // end of startTiming

    void finishTiming ()
      {
      active = false;
      Serial.print ("Capacitance = ");
      float capacitance = (float) timerCounts * 1000.0 / 16.0 / resistance;
      Serial.print (capacitance);
      Serial.println (" nF");
      triggered = false;
      delay (3000);
      }  // end of finishTiming

    void loop ()
      {
      // start another test?
      if (!active)
        startTiming ();

      // if the ISR noted the time interval is up, display results
      if (active && triggered)
        finishTiming ();

      }  // end of loop

title: understanding timer overflow detection code

Answers: 1

body:
>  'Naively' I would guess that, as soon as the analog comparator ISR is
>  called, the timer stops incrementing

It doesn't. The timer stops only when you ask it to stop.

Now, consider this scenario:

* `overflowCount` = 0, `TCNT1` = 0xfffc
* the `ANALOG_COMP` interrupt fires, which automatically disables
  servicing nested interrupts
* while `ISR(ANALOG_COMP_vect)` is executing its prologue (saving the
  execution context), Timer 1 overflows, which sets the `TOV1` flag, but
  the corresponding interrupt is for now pending
* when `timer1CounterValue = TCNT1;` gets executed, `TCNT1` is now
  0x0008.

At this point, we have `overflowCount` = 0 and `timer1CounterValue` =
0x0008. If we have no provision for detecting the overflow, we will
grossly underestimate the time. This can be fixed by accounting for the
missed overflow as

<!-- language: lang-c++ -->

    // if just missed an overflow
    if (TIFR1 & bit(TOV1))
        overflowCopy++;

The is still an issue however. Think of what would happen if the timer
overflows after executing `timer1CounterValue = TCNT1;` but before
reading the `TOV1` flag. Then we would unduly increment `overflowCopy`.
This is why the code tests for
`(TIFR1 & bit(TOV1)) && timer1CounterValue < 256`. There is no reason
for choosing this particular small value, other than the test being
easier to perform in assembly. The compiler is probably smart enough to
notice it doesn't need to do a subtraction for this particular value.


body: The ATmega328p can run on 5v but will it cause problems if it runs on 3.3 v and one input signal is 5v?

title: 5v input on ATmega328p running on 3.3v

Answers: 2

body: The voltage at any input *must* be less than VCC+0.3V unless it is restricted to only a few milliamperes (so it doesn't burn out the clamping diode). Use a proper voltage translator if it is available, otherwise use a 1kohm or greater resistor (at the cost of life expectancy for the MCU).

body:
Logic levels can be different across differently made integrated circuits and processors.  You should not directly connect differently powered devices together.  Logic level differences (as described [here][1]) should be dealt with using logic level converting devices such as [this one][2].

  [1]: https://learn.sparkfun.com/tutorials/logic-levels
  [2]: https://www.sparkfun.com/products/12009


body:
I am planning to buy a [formaldehyde sensor][1] and I would like to connect it to an **Arduino Uno** board (and later to a Raspberry). As far as I know, the sensor comes in a small box/bag without any other external components (e.g. amplifiers etc.). So I will end up having in my hand a sensor with two copper terminals for connection (see image below):

[![enter image description here][2]][2]

Is it possible to connect this to an Arduino board without having a connection scheme? If yes, where do I connect the two terminals of this sensor to the 5V, GND and the A## ports? Also, how to translate the voltage coming from the sensor to ppm (parts per million) only by having general specifications from the [manufacturer][3] and not some kind of table of conversion? Also, would I need an external component for this? If yes, which component?

I know that this question sounds very stupid, but so far I've used sensors that come with a code on [Seeed Grove][4] with a clear description and I assumed that the code is there because there is a link between the producer of a certain sensor and Groove. Thank you!

FYI: The producer writes some things about the sensor but that doesn't help me a lot:

> This sensor is of the two-electrode electrochemical type, operating by the
diffusion principle and as such requires no external sampling hardware. In
the presence of formaldehyde gas a small direct current is produced; the
sensor requires no power supply of its own but this current requires
amplification to make it readable using external data collection
equipment.

  [1]: https://www.dart-sensors.com/product/economy-formaldehyde-sensor/
  [2]: https://i.stack.imgur.com/DZBwe.png
  [3]: https://dart-sensors.com/wp/wp-content/uploads/2014/10/HCHOSensorDatasheet.pdf
  [4]: http://wiki.seeed.cc/Grove-HCHO_Sensor/

title: Connect a sensor to Arduino without knowing much info about the sensor

Answers: 1

body:
You have linked to the [datasheet][1] of the sensor.

In the datasheet, look at the "Application Circuit" section. You must build this circuit. The sensor produces a very small electric current, and the application circuit is high-gain amplifier to translate that very small electric current to a varying voltage you can sample with the Arduino ADC.

Note on the circuit, the wire labled "To ADC" -- that is the part which you connect to your arduino.

As for calibration, the datasheet itself notes that the process is non-trivial, or that they can perform a calibration, for an additional fee, at the time you order a batch of sensors. Presumably their calibration will include the precise resistor values used to set the gain of the amplifier, and also an equation to associate PPM values to the analog voltage provided at the "To ADC" wire.

As for reading the circuit diagram (schematic), you may already know resistors and capacitors. For the other items, search online for the part numbers given, to find out what they are.

The datasheet also notes that the application circuit is available pre-built from the sensor manufacturer. You may want to contact them to determine how to purchase one for yourself.

Most electronics products have a datasheet that explains all you typically need to know about the device, such as it's operating parameter minima and maxima, typical values, typical outputs, etc. This sensor is no different, except that the calibration procedure is not described in great detail due to the complexity.

  [1]: https://dart-sensors.com/wp/wp-content/uploads/2014/10/HCHOSensorDatasheet.pdf


body:
[![Circuit designed to work with ATtiny85][1]][1]Push a tactile switch to cycle through several different patterns on the LED strips. I want to modify the Arduino code so that I can use the ATtiny85 instead.
*****The code posted here works on the Arduino Uno with a 10k pull-up resistor wired to the push button at pin 11 on the Arduino.

<!-- language: lang-cpp -->

    /***************************************************************************/
    //            Hardware: RadioShack Tricolor LED Strip
    //            Arduino IDE: Arduino-1.0
    //            Date:      April 17, 2013
    //            Copyright© 2013 RadioShack Corporation
    //
    //  This library is free software; you can redistribute it and/or
    //  modify it under the terms of the GNU Lesser General Public
    //  License as published by the Free Software Foundation; either
    //  version 2.1 of the License, or (at your option) any later version.
    //
    //  This library is distributed in the hope that it will be useful,
    //  but WITHOUT ANY WARRANTY; without even the implied warranty of
    //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    //  Lesser General Public License for more details.
    //
    //  You should have received a copy of the GNU Lesser General Public
    //  License along with this library; if not, see <http://www.gnu.org/licenses/>
    //
    /*****************************************************************************/

    #include <avr/pgmspace.h>

    // ******** DEBUG ==== should auto config to adapt different mother board *********
    #define DATA_1 (PORTC |=  0X01)    // DATA 1    // for UNO
    #define DATA_0 (PORTC &=  0XFE)    // DATA 0    // for UNO
    #define STRIP_PINOUT (DDRC=0xFF)    // for UNO

    int val = 0; //variable to read button pin value
    int buttonPin = 11; //button pin variable, 11 on the Arduino
    int sequence = 1; //variable to hold current sequence

    PROGMEM const unsigned long pattern_test_blue_comet_red_bg[][20] = {
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},

    };

    PROGMEM const unsigned long pattern_test_disco[][20] = {
      {0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011},
      {0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022},
      {0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033},
      {0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044},
      {0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055},
      {0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066},
      {0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077},
      {0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088},
      {0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099},
      {0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa},
      {0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb},
      {0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc},
      {0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd},
      {0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000},
      {0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000},
      {0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000},
      {0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000},
      {0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000},
      {0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000},
      {0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000},
      {0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000},
      {0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000},
      {0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000},
      {0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000},
      {0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000},
      {0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000},
      {0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000},
      {0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000},
      {0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100},
      {0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200},
      {0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300},
      {0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400},
      {0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500},
      {0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600},
      {0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700},
      {0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800},
      {0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900},
      {0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00},
      {0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00},
      {0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00},
      {0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00},
      {0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00},
      {0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00},
    };

    PROGMEM const unsigned long pattern_test_pink[][20] = {
      {0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff},
    };

    PROGMEM const unsigned long pattern_test_purple[][20] = {
      {0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66},
    };

    PROGMEM const unsigned long pattern_test_blue[][20] = {
      {0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00},
    };

    PROGMEM const unsigned long pattern_test_green[][20] = {
      {0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000},
    };

    PROGMEM const unsigned long pattern_test_yellow[][20] = {
      {0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff},
    };

    PROGMEM const unsigned long pattern_test_white[][20] = {
      {0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff},
    };

    PROGMEM const unsigned long pattern_test_red[][20] = {
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
    };

    // ***********************************************************************************************************
    // *
    // *                            Power Up Init.
    // *
    // *
    // ***********************************************************************************************************
    void setup() {

      STRIP_PINOUT;        // set output pin - DEBUG: should auto detect which mother board for use

      reset_strip();
      //noInterrupts();

    }

    // ***********************************************************************************************************
    // *
    // *                            Main Loop
    // *
    // *
    // ***********************************************************************************************************
    void loop()
    {

      val = digitalRead(buttonPin);
      if (val == LOW)
      {
        if (sequence == 9)
        {
          sequence = 1;
        } else
        {
          sequence++;
        }
        delay(200);
      }

      switch (sequence)
      {
        case 1:
          send_1M_pattern(pattern_test_pink, 1, 5);
          delay(1);
          break;
        case 2:
          send_1M_pattern(pattern_test_purple, 1, 5);
          delay(1);
          break;
        case 3:
          send_1M_pattern(pattern_test_blue, 1, 5);
          delay(1);
          break;
        case 4:
          send_1M_pattern(pattern_test_green, 1, 5);
          delay(1);
          break;
        case 5:
          send_1M_pattern(pattern_test_yellow, 1, 5);
          delay(1);
          break;
        case 6:
          send_1M_pattern(pattern_test_white, 1, 5);
          delay(1);
          break;
        case 7:
          send_1M_pattern(pattern_test_red, 1, 5);
          delay(1);
          break;
        case 8:
          send_1M_pattern(pattern_test_blue_comet_red_bg, 43, 45);
          delay(1);
          break;
        case 9:
          send_1M_pattern(pattern_test_disco, 45, 5);
          delay(1);
          break;
      }

      //delay(1);
    }

    /*******************************************************************************
       Function Name  : send_1M_pattern
       Description    : Transmit pattern to whole 1 meter strip
       Input          : pointer to ROM pattern; pattern length; frame rate
       Output         : None
       Return         : None
     *******************************************************************************/
    void send_1M_pattern(const unsigned long data[][20], int pattern_no, int frame_rate)
    {
      int i = 0;
      int j = 0;
      uint32_t temp_data;

      for (i = 0; i < pattern_no; i++)
      {
        noInterrupts();
        for (j = 0; j < 20; j++)
        {
          temp_data = pgm_read_dword_near(&data[i][j]);
          send_strip(temp_data);
        }
        interrupts();

        delay(frame_rate);

      }
    }

    /*******************************************************************************
       Function Name  : send_strip
       Description    : Transmit 24 pulse to LED strip
       Input          : 24-bit data for the strip
       Output         : None
       Return         : None
     *******************************************************************************/
    void send_strip(uint32_t data)
    {
      int i;
      unsigned long j = 0x800000;

      for (i = 0; i < 24; i++)
      {
        if (data & j)
        {
          DATA_1;
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");

          /*----------------------------*/
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          /*----------------------------*/
          DATA_0;
        }
        else
        {
          DATA_1;
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          DATA_0;
          /*----------------------------*/
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          __asm__("nop\n\t");
          /*----------------------------*/
        }

        j >>= 1;
      }
    }

    /*******************************************************************************
       Function Name  : reset_strip
       Description    : Send reset pulse to reset all color of the strip
       Input          : None
       Output         : None
       Return         : None
     *******************************************************************************/
    void  reset_strip()
    {
      DATA_0;
      delayMicroseconds(20);
    }

  [1]: https://i.stack.imgur.com/p4QDa.jpg

title: How can I modify Arduino code to work with ATtiny85?

Answers: 1

body:
Try replacing the lines

    #define DATA_1 (PORTC |=  0X01)    // DATA 1    // for UNO
    #define DATA_0 (PORTC &=  0XFE)    // DATA 0    // for UNO
    #define STRIP_PINOUT (DDRC=0xFF)    // for UNO
    int buttonPin = 11; //button pin variable, 11 on the Arduino

with

    #define DATA_1 (PORTB |=  0X01)    // DATA 1    // on PB0
    #define DATA_0 (PORTB &=  0XFE)    // DATA 0    // on PB0
    #define STRIP_PINOUT (DDRB=0x01)    // PB0 as output
    int buttonPin = 3; //button pin variable, pin 3 = PB3

Connect the push button between PB3 and GND, with an external pullup.
Connect PB0 to the data input of the LED strip.

If the program doesn't fit in the flash, try removing one of the largest
patterns. Otherwise, if it almost fits, you could try to optimize it to
make it smaller.

------------------------------------------------------------------------

**Edit**: I modified the original code and added some optimizations.
Notably, I removed all dependencies to the Arduino core, which makes it
significantly smaller. Now it fits in the flash memory of the ATtiny85
without removing any pattern.

This is a polyglot: it should compile either as a .ino sketch, as a
plain C program, or as a C++ program.

Here is the code:

    /***************************************************************************/
    //            Hardware: RadioShack Tricolor LED Strip
    //            Arduino IDE: Arduino-1.0
    //            Date:      April 17, 2013
    //            Copyright© 2013 RadioShack Corporation
    //
    //  This library is free software; you can redistribute it and/or
    //  modify it under the terms of the GNU Lesser General Public
    //  License as published by the Free Software Foundation; either
    //  version 2.1 of the License, or (at your option) any later version.
    //
    //  This library is distributed in the hope that it will be useful,
    //  but WITHOUT ANY WARRANTY; without even the implied warranty of
    //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    //  Lesser General Public License for more details.
    //
    //  You should have received a copy of the GNU Lesser General Public
    //  License along with this library; if not, see <http://www.gnu.org/licenses/>
    //
    /*****************************************************************************/
    // Modified to work on an ATtiny85 by Edgar Bonet -- 2017-12-12.
    //
    // Wiring:
    //   - connect a push button between PB3 and GND
    //   - connect PB0 to the data input of the LED strip
    //
    // Compile:
    //   avr-gcc -mmcu=attiny85 -Os -Wall -Wextra -DF_CPU=8000000
    //   Tricolor-LED-Strip.c -o Tricolor-LED-Strip.elf
    /*****************************************************************************/

    #include <avr/pgmspace.h>
    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <util/delay.h>

    // Change this if you want to use different pins.
    #define DATA_PIN   PB0
    #define BUTTON_PIN PB3

    void send_1M_pattern(const unsigned long data[][20], uint8_t pattern_no, uint8_t frame_rate);
    void send_strip(uint32_t data);
    void reset_strip();

    static void short_delay(uint8_t ms)
    {
      while (ms--) _delay_ms(1);
    }

    PROGMEM const unsigned long pattern_test_blue_comet_red_bg[][20] = {
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100, 0x00ff00},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x001100},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x0000ff, 0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x00ff00, 0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x001100, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},

    };

    PROGMEM const unsigned long pattern_test_disco[][20] = {
      {0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011, 0x000011},
      {0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022, 0x000022},
      {0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033, 0x000033},
      {0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044, 0x000044},
      {0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055, 0x000055},
      {0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066, 0x000066},
      {0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077, 0x000077},
      {0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088, 0x000088},
      {0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099, 0x000099},
      {0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa, 0x0000aa},
      {0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb, 0x0000bb},
      {0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc, 0x0000cc},
      {0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd, 0x0000dd},
      {0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee, 0x0000ee},
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
      {0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000, 0x110000},
      {0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000, 0x220000},
      {0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000, 0x330000},
      {0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000, 0x440000},
      {0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000, 0x550000},
      {0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000, 0x660000},
      {0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000, 0x770000},
      {0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000, 0x880000},
      {0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000, 0x990000},
      {0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000, 0xaa0000},
      {0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000, 0xbb0000},
      {0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000, 0xcc0000},
      {0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000, 0xdd0000},
      {0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000, 0xee0000},
      {0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000},
      {0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100, 0x001100},
      {0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200, 0x002200},
      {0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300, 0x003300},
      {0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400, 0x004400},
      {0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500, 0x005500},
      {0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600, 0x006600},
      {0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700, 0x007700},
      {0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800, 0x008800},
      {0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900, 0x009900},
      {0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00, 0x00aa00},
      {0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00, 0x00bb00},
      {0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00, 0x00cc00},
      {0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00, 0x00dd00},
      {0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00, 0x00ee00},
      {0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00},
    };

    PROGMEM const unsigned long pattern_test_pink[][20] = {
      {0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff, 0x00ffff},
    };

    PROGMEM const unsigned long pattern_test_purple[][20] = {
      {0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66, 0x00cc66},
    };

    PROGMEM const unsigned long pattern_test_blue[][20] = {
      {0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00, 0x00ff00},
    };

    PROGMEM const unsigned long pattern_test_green[][20] = {
      {0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000},
    };

    PROGMEM const unsigned long pattern_test_yellow[][20] = {
      {0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff, 0xff00ff},
    };

    PROGMEM const unsigned long pattern_test_white[][20] = {
      {0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff},
    };

    PROGMEM const unsigned long pattern_test_red[][20] = {
      {0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff, 0x0000ff},
    };

    static const struct {
      const unsigned long (*data)[20];
      uint8_t pattern_no;
      uint8_t frame_rate;
    } patterns[9] = {
      {pattern_test_pink, 1, 5},
      {pattern_test_purple, 1, 5},
      {pattern_test_blue, 1, 5},
      {pattern_test_green, 1, 5},
      {pattern_test_yellow, 1, 5},
      {pattern_test_white, 1, 5},
      {pattern_test_red, 1, 5},
      {pattern_test_blue_comet_red_bg, 43, 45},
      {pattern_test_disco, 45, 5}
    };

    // ***********************************************************************************************************
    // *
    // *                            Main Program
    // *
    // *
    // ***********************************************************************************************************
    int main(void)
    {
      uint8_t sequence = 0; //variable to hold current sequence

      DDRB |= _BV(DATA_PIN);     // DATA_PIN as output
      PORTB |= _BV(BUTTON_PIN);  // internal pullup on button pin
      reset_strip();

      for (;;) {
        if ((PINB & _BV(BUTTON_PIN)) == 0) {  // if the button is pressed
          if (++sequence == 9)
            sequence = 0;
          short_delay(200);
        }
        send_1M_pattern(
          patterns[sequence].data,
          patterns[sequence].pattern_no,
          patterns[sequence].frame_rate
        );
        short_delay(1);
      }
    }

    /*******************************************************************************
       Function Name  : send_1M_pattern
       Description    : Transmit pattern to whole 1 meter strip
       Input          : pointer to ROM pattern; pattern length; frame rate
       Output         : None
       Return         : None
     *******************************************************************************/
    void send_1M_pattern(const unsigned long data[][20], uint8_t pattern_no, uint8_t frame_rate)
    {
      int i = 0;
      int j = 0;
      uint32_t temp_data;

      for (i = 0; i < pattern_no; i++)
      {
        for (j = 0; j < 20; j++)
        {
          temp_data = pgm_read_dword_near(&data[i][j]);
          send_strip(temp_data);
        }

        short_delay(frame_rate);

      }
    }

    /*******************************************************************************
       Function Name  : send_strip
       Description    : Transmit 24 pulse to LED strip
       Input          : 24-bit data for the strip
       Output         : None
       Return         : None
     *******************************************************************************/
    void send_strip(uint32_t data)
    {
      int i;
      unsigned long j = 0x800000;

      for (i = 0; i < 24; i++)
      {
        if (data & j)
        {
          PORTB |= _BV(DATA_PIN);
          _delay_us(1.75);
          PORTB &= ~_BV(DATA_PIN);
        }
        else
        {
          PORTB |= _BV(DATA_PIN);
          _delay_us(0.563);
          PORTB &= ~_BV(DATA_PIN);
          _delay_us(0.188);
        }

        j >>= 1;
      }
    }

    /*******************************************************************************
       Function Name  : reset_strip
       Description    : Send reset pulse to reset all color of the strip
       Input          : None
       Output         : None
       Return         : None
     *******************************************************************************/
    void  reset_strip()
    {
      PORTB &= ~_BV(DATA_PIN);
      _delay_us(20);
    }


body:
Building upon my previously solved question https://arduino.stackexchange.com/questions/47652/ultrasonic-sensor-range-finder-help-solved.

Is there a better way to make the LED blink than using a delay and stopping all the rest of the code? For example, the LED is set to turn on, then shortly after turn off. Is there a better way to do this?

For example, if the LED is turned on, it then delays the code, which means it has to wait for the delay to be over, turn off, then change its pattern. For example, allow the Arduino to interrupt the blink with a new interval blink, mid blink? I'm sorry if this is confusing, it's tough to explain.

Simply put, is there a better function than `delay()` that can allow the Arduino to suddenly change the state of the LED while it is waiting on a `delay()` to finish?

The code I'm working on is this:

<!-- language: lang-cpp -->

    #include <NewPing.h>
    #define TRIGGER_PIN  15
    #define ECHO_PIN     2
    #define MAX_DISTANCE 500
    int LED1 = 3;
    int LED2 = 16;
    int LED3 = 9;
    int LED4 = 6;

    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

    void setup() {
      pinMode(LED1, OUTPUT);
      pinMode(LED2, OUTPUT);
      pinMode(LED3, OUTPUT);
      pinMode(LED4, OUTPUT);
    }

    void loop() {
      delay(50);
      unsigned int uS = sonar.ping_median(10);
      int IN = sonar.convert_in(uS);
      if (IN <= 5) {
        analogWrite(LED4, 255);
        delay(100);
        analogWrite(LED4, 0);
      } else if (IN >= 5 && IN <= 12) {
        analogWrite(LED4, 1);
        delay(200);
        analogWrite(LED4, 0);
      } else if (IN >= 13) {
        analogWrite(LED4, 100);
        delay(300);
        analogWrite(LED4, 0);
      }
    }

title: Can I improve this code (replacing delays with something else)?

Answers: 3

body:
In general, if you want two separate tasks (like controlling the LED and do something else) 'simultaneously', you should not use delay.

Instead use a long int variable to keep the time since something happened (like switching the LED color in your case). Than check in the loop how much time has passed and act on it.

E.g.

When you call analog writes with non zero values, set the variable to the current time. Than instead of the delay check if the current time minus the variable < 100 or 200 or 300 depending on the value you need and than set the analog write back to 0 (switching off the LED). In the rest of the loop you can do other tasks.

body:
You can use [millis()][1] to get a timer:<br>
[millis()][1] Returns the number of milliseconds since the Arduino board began running the current program.

    void loop(){
        if(millis() % 100 == 0){//%(modullo) is the rest of a division. 19=9 because10/10 = 1 and the rest is 9
            //you have wait 100 millisecond. When millis()0 == 0 millis() is a multiple of 100.
        }
    }

For your code you can do this:

    int LED1 = 3;
    int LED1 = 3;
    int LED2 = 16;
    int LED3 = 9;
    int LED4 = 6;

    //Ligth on -> 1 light off -> 0
    int LED1Stat = 0;
    int LED2Stat = 0;
    int LED3Stat = 0;
    int LED4Stat = 0;

    void setup() {
      // put your setup code here, to run once:
      pinMode(LED1, OUTPUT);    //every 100 ms
      pinMode(LED2, OUTPUT);    //every 250 ms
      pinMode(LED3, OUTPUT);    //every 500 ms
      pinMode(LED4, OUTPUT);    //every 1000 ms

    }

    void loop() {
        //for no Delay
        if(millis()0 = 0){
            LED1Stat = !LED1Stat;
            digitalWrite(LED1, LED1Stat);
        }
        if(millis()%0 = 0){
            LED2Stat = !LLED2Stat;
            digitalWrite(LED2, LED2Stat);
        }
        if(millis()P0 = 0){
            LED3Stat = !LED3Stat;
            digitalWrite(LED3, LED3Stat);
        }
        if(millis()00 = 0){
            LED4Stat = !LED4Stat;
            digitalWrite(LED4, LED4Stat);
        }
    }
[EDIT]

    long prevMillis = 0;
    void loop(){
        if(millis()-prevMillis >= 100){
            LED1Stat = !LED1Stat;
            digitalWrite(LED1, LED1Stat);
            prevMillis = millis();
        }
        //...

    }

  [1]: https://www.arduino.cc/reference/en/language/functions/time/millis/

body:
I think the delay function will wait until enough clock cycles are done. The function counts the cycles and you must wait for enough.

The timer/counters are a part of a microcontroller and are used for example to measure the time between two events or generating interrupt after a defined time. The advantage is you can start the timer and the code after it must not wait. When the time is over you can simply generate an interrupt and execute small code in the interrupt handler.


body:
I am not very experienced with Arduino and I am trying to learn it. I was wondering what is the easiest and most effective way to calculate speed and log it every second so to say. This would be mounted in a model rocket to see what speeds it can reach. How would I achieve this?

Would it be hard to send over RF to see it in real time?

Thanks in Advance

title: How to use an Arduino to measure speed of rocket

Answers: 2

body:
Quite different questions, but you need two items:

- A gyroscope/accellerometer, I don't think this should be a problem. You need to check beforehand if the Arduino is fast enough, since a rocket acceleration is probably very high.

- An RF transceiver, there are several types which work over big distances, but I don't have experience while they move fast. Maybe radio signals might get distorted, but for that hopefully someone has a better answer. Probably you cannot use a (big) external antenna which extends outside the rocket.

body:
You can use an [accelerometer][1] or a [barometre][2] for measure speed and for RF you can use:

 - [Radio NRF24L01][3]
 - [wifi ESP8266][4]
 - [bluetooth HC-06][5]

  [1]: https://diyhacking.com/arduino-mpu-6050-imu-sensor-tutorial/
  [2]: http://arduinolearning.com/code/bmp180-barometric-pressure-sensor-example.php
  [3]: http://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/
  [4]: http://www.instructables.com/id/Quick-Start-to-Nodemcu-ESP8266-on-Arduino-IDE/
  [5]: https://create.arduino.cc/projecthub/user206876468/arduino-bluetooth-basic-tutorial-d8b737


body:
I want to use an Arduino Uno to control the LED light strips, based on the input signal from a robot controller. The robot controller sends a digital signal with "HIGH" of 24 V and "LOW" of 0 V.  I have thought of using an optocoupler between the robot controller and the Arduino to reduce the voltage from 24 V to 5 V, suitable for the Arduino pin.

Can I connect the optocoupler's emitter to the Arduino ground?

The LED strips work on 12V DC and at 2000mA. If I power the Arduino with 12V DC power source connected to the DC jack, can I give the power to the LED's also using the V-in pin of the Arduino?

Please look at my circuit and tell me where I went wrong and why?

[![Circuit schematic][1]][1]

  [1]: https://i.stack.imgur.com/iU5P8.png

title: Connect optocoupler 4N35 to Arduino Uno to control LED light strips

Answers: 1

body:
> Can i connect the optocoupler's emmitter to the arduino ground?

Yes. Don't forget to either enable the internal pullup on the GPIO pin or use an external pullup on the collector.

>  If i power the arduino with 12 V D.C power source connected to the D.C jack, can i give the power to the LEDs also using the V-in pin of the arduino?

Not at the current rating you are talking about, no. The header is only rated for 1A, and the diode on the barrel jack input is also rated for only 1A.  You would need to split the LED power off from the incoming power *before* it goes into the Arduino.

The way you have your MOSFETs wired at the moment is wrong. The moment you turn one on it will let the Magic Smoke escape. You are using them to short circuit the LEDs, which is very very bad.

Each one should be wired in series with the LED between the cathode and ground:

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/h0FN5.png)

<!-- End schematic -->


body:
    int ledPin1 = 1;
    int ledpin2 = 2;
    int ledpin3 = 3;
    int ledpin4 = 4;
    int ledpin5 = 5;
    int ledpin6 = 6;

    void setup()
    {
      //initialize pins as outputs
      pinMode(ledPin1, OUTPUT);
      pinMode(ledPin2, OUTPUT);
      pinMode(ledPin3, OUTPUT);
      pinMode(ledPin4, OUTPUT);
      pinMode(ledPin5, OUTPUT);
      pinMode(ledpin6, OUTPUT);
    }

    void loop()
    {
      digitalWrite(ledPin1, HIGH);
      delay(200);
      digitalWrite(ledPin2, HIGH);
      delay(200);
      digitalWrite(ledPin3, HIGH);
      delay(200);
      digitalWrite(ledPin4, HIGH);
      delay(200);
      digitalWrite(ledPin5, HIGH);
      delay(200);
      digitalWrite(ledpin5, LOW);
      digitalWrite(ledpin4, LOW);
      digitalWrite(ledpin3, LOW);
      digitalWrite(ledpin2, LOW);
      digitalWrite(ledpin1, LOW);
      digitalWrite(ledPin5, HIGH);
      delay(200);
      digitalWrite(ledPin4, HIGH);
      delay(200);
      digitalWrite(ledPin3, HIGH);
      delay(200);
      digitalWrite(ledPin2, HIGH);
      delay(200);
      digitalWrite(ledPin1, HIGH);
      delay(200);
    }

title: The code is showing a error that "ledpin2 is not declared in the scope"

Answers: 2

body:
You mix capitals with non capital characters.

The case of characters in variable names are important, so ledPin2 is a different variable than ledpin2.

Also, never mix similar names (unless it is trivial). Either always use ledpinx or ledPinx, not sometimes the first and sometimes the second version.

camelCasing is normally used for local variables, means the first sub-word starts with a lower case, rest with upper case, thus led-pin will become ledPin.

Pascal case is the other way: that would become LedPin in your case.

For global variables I tend to use PascalCasing, or if it is within one file, prefixed camelCasing with an underscore.

body:
I have corrected your code it was just because you mixed capital and lowercase letters while declaring `ledPin`. Keep it same everywhere in `setup()` and `loop()`.

<!-- language: lang-cpp -->

    int ledPin1 = 1;
    int ledPin2 = 2;
    int ledPin3 = 3;
    int ledPin4 = 4;
    int ledPin5 = 5;
    int ledPin6 = 6;

    void setup()
    {
        //initialize pins as outputs
        pinMode(ledPin1, OUTPUT);
        pinMode(ledPin2, OUTPUT);
        pinMode(ledPin3, OUTPUT);
        pinMode(ledPin4, OUTPUT);
        pinMode(ledPin5, OUTPUT);
        pinMode(ledPin6, OUTPUT);
    }

    void loop()
    {
        digitalWrite(ledPin1, HIGH);
        delay(200);
        digitalWrite(ledPin2, HIGH);
        delay(200);
        digitalWrite(ledPin3, HIGH);
        delay(200);
        digitalWrite(ledPin4, HIGH);
        delay(200);
        digitalWrite(ledPin5, HIGH);
        delay(200);
        digitalWrite(ledPin5, LOW);
        digitalWrite(ledPin4, LOW);
        digitalWrite(ledPin3, LOW);
        digitalWrite(ledPin2, LOW);
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin5, HIGH);
        delay(200);
        digitalWrite(ledPin4, HIGH);
        delay(200);
        digitalWrite(ledPin3, HIGH);
        delay(200);
        digitalWrite(ledPin2, HIGH);
        delay(200);
        digitalWrite(ledPin1, HIGH);
        delay(200);
    }


body:
Here's the scenario:
We have 1 arduino uno accepting DMX and converting that to a signal that is being sent out digitally (PIN 3). The digital signal then goes to several IR LED senders that control 3,200 IR, color-changing candles. I've recently added some more senders, and now some of the senders are not working (even some that were working before). I assume this is because the digital signal has been weakened due to me splitting it so many times.

I'd like to add another arduino to control half of the IR senders. I obviously already have a cable running to every device, but I know of a perfect place to "interject" the new arduino. Is this possible? Can the second arduino essentially "repeat" or decode and re-encode the digital signal? If so, what pins am I looking at and will I need any special code?

Thanks for the help!

title: Need to "Extend" a Arduino Digital Signal

Answers: 2

body:
The scenario you are referring to - connecting one output to many devices - is called the *fan-out*. Yes, a GPIO pin has a limited amount of *drive* which limits the number of devices in the *fan-out*.

There are two problems that are caused by excess fan-out:

1. Excess current draw from resistive loads
2. Excess capacitance from logic loads

The former is evident when you have too many LEDs connected directly to an output (with resistors, of course). The combined current draw of the LEDs exceeds the current the IO pin can provide and either damage the pin or the LEDs go dimmer than would be desired.

The latter is more evident when working with communication signals. The excess capacitance imposed by each gate attached to the output causes a low-pass filter effect which can filter out high-frequency signals or corrupt the waveforms by removing higher frequency components and "curving off" the nice clean square waves.

In normal logic systems it's common to use *line drivers* or *buffers* to allow the connection of more devices to a single signal. Devices such as the 74HC244, which is 8 buffers in one chip, are commonly employed. You can connect the inputs of all 8 buffers to one Arduino output, and each output from the buffer mirrors the input exactly and can connect to more devices than an Arduino can (each output has an extra 10mA steady-state drive capacity than the Arduino).

And yes, you can even connect the output of one buffer to the inputs of other buffers to give even more capacity.

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/VxNif.png)

<!-- End schematic -->

body: The buffer is a good idea, each pin on an arduino can deliver 20ma, but then the chip can over heat, and you can't drive every output to 20ma, so the buffer chip is the way to go. Just consider the speed of the buffer when you are sending data. There are many chips that can do it, and many that might not be able to do it. So look at the speed of the chip from input to output. Then again, the arduino may not be able to keep up. So consider a PIC, some PIC's are really fast compared to an arduino.


body:
I am working on a puzzle for my nephew. I currently have an arduino mega, SD card reader and keypad. Everything is wired correctly and I have it currently programmed so when you enter the right password than an audio file plays and a green LED lights up. Where I am struggling is I do not know how to program it so that when the wrong pass code is entered then my red LED light flashes and the code resets to position 0. I also noticed that my current password is 1,2,3 and when I add a random number between my pass code, say, 1,5,2,3 or even 1,3,2,2,3 then the audio file still plays and my green LED lights up. Any suggestions?

    #include <Keypad.h>
    #include <SD.h>
    #include <TMRpcm.h>
    #define SD_ChipSelectPin 53

    TMRpcm tmrpcm;
    char* password = "123";
    int position = 0;
    const byte ROWS = 4;
    const byte COLS = 4;
    char keys[ROWS][COLS] = {
      {'1','2','3','A'},
      {'4','5','6','B'},
      {'7','8','9','C'},
      {'*','0','#','D'}
    };

    byte rowPins[ROWS] = { 8, 7, 6, 9 };
    byte colPins[COLS] = { 5, 4, 3, 2 };
    Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
    int R = 12;
    int G = 13;

    void setup(){
      pinMode(R, OUTPUT);
      pinMode(G, OUTPUT);

      LockedPosition(true);
      tmrpcm.speakerPin = 46;
      if (!SD.begin(SD_ChipSelectPin)) {
        return;
      }
    }

    void loop()
    {
      char key = keypad.getKey();
      if (key == '*' || key == '#')
      {
        position = 0;
        LockedPosition(true);
      }
      if (key == password[position])
      {
        position ++;
      }
      if (position == 3)
      {
        LockedPosition(false);
      }
      delay(100);
    }

    void LockedPosition(int locked)
    {
      if (locked)
      {
        digitalWrite(R, HIGH);
        digitalWrite(G, LOW);
        position=0;
      }
      else
      {
        digitalWrite(R, LOW);
        digitalWrite(G, HIGH);
        tmrpcm.setVolume(6);
        tmrpcm.play("matt.wav"); ;
        delay(10000);
        digitalWrite(G,LOW);
      }
    }

title: Getting my keypad to reset when wrong password is entered

Answers: 2

body: You have the part checking if the key equals the position in the password and if so you increment the position.  But if it is not equal then you don't do anything.  You should probably have an else there that resets the position to 0 and tells the user they entered the wrong password.

body:
Define two Strings:

    String password = "123";
    String answer = "";

replace the loop function with:

    void loop()
    {
            char key = keypad.getKey(); // init. variable key keypad is non blocking
            while(key == NO_KEY)                 // we got no key press? -> do again
            {
                    key = keypad.getKey();
                    delay(100);
            }
            answer.concat(key);         //add key to answer
            if(answer.equals(password)) //password OK
            {
                    LockedPosition(false);
                    answer="";
            }
            else
            {
                    LockedPosition(true);
            }

            if (answer.length() > password.length()) { // answer is different and bigger than password
                                                       // can't become the right answer
                    answer = "";
            }

            if (key == '*' || key == '#')
            {
                    LockedPosition(true);
                    answer="";
            }

    }

That should do the job.


body:
First of all, my Arduino Uno R3 isn't genuine.

At some moment when I was playing with it, the Arduino stopped working. It was connected to a external 12V power supply on the 2.1mm plug. A single digital output was connected to a base of a BJT, which was being used as a switch. I checked all the voltage differences and amount of current around the BJT with my multimeter, and I made sure nothing ever exceeds the maximum rating.

One thing, I had a jumper wire connected to the 5V, and it might have accidentally got shorted with GND while poking around.

Currently, the Arduino won't start up when given external power supply soley, be it a 2.1mm plug or VIN pin. The ON light is not on. I tried to measure the current it consumes, but the value from the multimeter changes when I switch the measure range -- I suppose this is because the current is so small that the so-small resistance of the multimeter affects the current. The 5V pin, when connected to GND through a 1K ohm resistor, says about 50 mV.

However, when the USB is connected, the board works alright, regardless of whether external power supply is connected. The 5V pin says quite 5V, but I see from the [schematic of Uno Rev. 3](https://www.arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf) that it is in fact just pulled from the USB power line, so it **does not** mean that the internal transformer circuitry is alright. When the USB gets disconnected while the USB and the external power supply is both connected, the board immediately turns off.

Am I good to regard this board as dead in some way? What do you think is broken?

And could there be any way to resusticate it?

title: Arduino not working on external power supply

Answers: 2

body: By shorting 5V to GND you have blown the 5V regulator on the board. Buy a new board unless you like reworking SMD components.

body:
You probably have shorted 5V to the Ground and it broke the voltage regulator on the Arduino. You should by a new one. [Original][1] one have more security than non genuine and they are not expensive.

  [1]: https://store.arduino.cc/arduino-uno-rev3


body:
I am working on a remote controlled vehicle based project. I am using a PS3 bluetooth controller for this purpose & am facing the problem described below. Any help would be appreciated.

Basically, the motors are connected to the MEGA which is connected to a USB Host Shield. A bluetooth dongle is connected to the shield. This dongle & shield enable MEGA to communicate with PS3 wirelessly. I am using the [USB Host 2.0][1] library available for Arduino on GitHub.

My code to take input from the PS3 is as follows:

    USB.Task();
    if ( PS3.PS3Connected || PS3.PS3NavigationConnected )
    {
        if ( PS3.getAnalogButton(UP) )
            Serial.println("UP");
        if ( PS3.getAnalogButton(DOWN) )
            Serial.println("DOWN");
        if ( PS3.getAnalogButton(LEFT) )
            Serial.println("LEFT");
        if ( PS3.getAnalogButton(RIGHT) )
            Serial.println("RIGHT");
    }

This is the code inside loop(). If anyone is wondering why getAnalogButton is used instead of getButtonClick, the reason is to enable the vehicle to move ahead as long as UP is pressed & so on. This was an improvisation on our part.

As can be seen, the function prints UP, DOWN, LEFT or RIGHT as long as they are pressed continuously. The problem is that it works perfect for a while. But then, it enters an infinite loop & stops taking input from the PS3.

Basically, the input is like

    UP
    UP
    UP
    UP
    UP
    UP
    UP
    .....
    LEFT
    LEFT
    LEFT
    // At this point it hangs without printing any further inputs.

Can someone help tackle this problem? It is essential for us to move the vehicle as long as the buttons are pressed & stop when button is released. Unfortunately, there is no feature to detect PRESSED or RELEASED state for PS3. Any help would mean a lot.

Also, we initially thought that the hang was because of overflowing the serial input. So, we removed all Serial messages & tested with LEDs. But, the same problem is still faced.

  [1]: https://github.com/felis/USB_Host_Shield_2.0

title: Remove hanging PS3 input via bluetooth to arduino

Answers: 0


body:
I have a board without network connection, then I bought an SP-WROOM-32 dev kit because it has network connection ability.

Is there any way that I use esp32 as a secure socket (just like calling `socket_connect()` and the ESP will be used?)

I know that my board can control the ESP with AT commands but I want a native way.

Thank and have a nice day.

title: Use ESP32 as a secure socket

Answers: 0