# Question
Title: How can I modify Arduino code to work with ATtiny85?
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.

```
/***************************************************************************/
//            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);
}

```

# Answer
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);
}

```
> 2 votes

---
Tags: arduino-uno, attiny85
---


# Question
Title: How to use an Arduino to measure speed of rocket
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

# Answer
> 1 votes
You can use an accelerometer or a barometre for measure speed and for RF you can use:

# Answer
> 0 votes
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.

---
Tags: arduino-uno, accelerometer, rf, datalogging, speed
---


# Question
Title: Arduino code is not working for unipolar stepper motor
I am using unipolar 1.8 degree stepper motor. I have written code to rotate stepper motor i.e. when A0 pin becomes HIGH it should rotate in clockwise and when A1 pin becomes HIGH it should move anti clockwise but motor is rotating only once when I am making A0/A1 HIGH and then stops. After that it is not rotating even if i am making A0, A1 pin high. I am very new to this please tell how to solve this problem. I am using microstepping drive, nema 17 stepper motor and Arduino Uno board.

```
#include <Stepper.h>

#define STEPS_PER_MOTOR_REVOLUTION 32

#define STEPS_PER_OUTPUT_REVOLUTION 32 * 200 //2048

Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 9, 8);
int  Steps2Take;
int buttonApin = A0;
int buttonBpin = A1;
int dirpin = 8;
int steppin = 9;
void setup()
{
  pinMode(buttonApin, INPUT);
  pinMode(buttonApin, INPUT);
  pinMode(dirpin, OUTPUT);
  pinMode(steppin, OUTPUT);
  small_stepper.setSpeed(1900);
}
void loop()
{
  int valA = digitalRead(buttonApin);

  if (valA == HIGH)
  { digitalWrite(dirpin, HIGH);
    for (int x = 0; x < 100; x++)
    { digitalWrite(steppin, HIGH);
      delayMicroseconds(1000);
      digitalWrite(steppin, LOW);
      delayMicroseconds(1000);
    }
  }
  int valB = digitalRead(buttonBpin);

  if (valB == HIGH)
  {
    digitalWrite(dirpin, LOW);
    for (int x = 0; x < 100; x++)
    {
      digitalWrite(steppin, LOW);
      delayMicroseconds(1000);
      digitalWrite(steppin, HIGH);
      delayMicroseconds(1000);
    }
  }
}

```

# Answer
> 2 votes
I have mentioned in the comments that you should read the buttons with `analogRead()`. But you can do it other way by simply connecting the button pin to digital inputs on arduino(any from 0-13). Analog pins are mostly used for accessing the sensor data as far as I know. I am correcting your code as below:

```
#include <Stepper.h>

#define STEPS_PER_MOTOR_REVOLUTION 32

#define STEPS_PER_OUTPUT_REVOLUTION 32 * 200 //2048

Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 9, 8);
int  Steps2Take;
int buttonApin = 4; //connect button to digital pin 4 on arduino
int buttonBpin = 5; //connect button to digital pin 5 on arduino
int dirpin = 8;
int steppin = 9;
void setup()
{
  pinMode(buttonApin, INPUT);
  pinMode(buttonApin, INPUT);
  pinMode(dirpin, OUTPUT);
  pinMode(steppin, OUTPUT);
  small_stepper.setSpeed(1900);
}
void loop()
{
  int valA = digitalRead(buttonApin);

  if (valA == HIGH)
  { digitalWrite(dirpin, HIGH);
    for (int x = 0; x < 100; x++)
    { digitalWrite(steppin, HIGH);
      delayMicroseconds(1000);
      digitalWrite(steppin, LOW);
      delayMicroseconds(1000);
    }
  }
  int valB = digitalRead(buttonBpin);

  if (valB == HIGH)
  {
    digitalWrite(dirpin, LOW);
    for (int x = 0; x < 100; x++)
    {
      digitalWrite(steppin, LOW);
      delayMicroseconds(1000);
      digitalWrite(steppin, HIGH);
      delayMicroseconds(1000);
    }
  }
}

```

---
Tags: arduino-uno, stepper
---


# Question
Title: Connect optocoupler 4N35 to Arduino Uno to control LED light strips
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?

# Answer
> 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:

simulate this circuit – Schematic created using CircuitLab
> 1 votes

---
Tags: arduino-uno, voltage-level, opto-isolator, led-strip
---


# Question
Title: Problem communicating between arduino UNO R3 and Mega 2560 via MAX485
I want to send data between Arduino Uno and Mega via MAX485.

When I set the data Enable pin to HIGH on Mega (to transmit data) and set the same pin on UNO to LOW (to receive data) I can read data from Mega into Uno properly. However, when I want to do it vice versa (send data from uno to mega) can't get any data from Uno into Mega. Tried different pins on both boards but still no answer.

This problem happens when I want to change data Enable pins to low or high inside loop(), I mean when I use for example Uno as permanent master and mega as permanent slave, it works properly but when I try to change them from slave to master on runtime, data cannot be sent from uno to mega!

PS: Im newbie on RS485 and MAX485. Here is my code in MEGA side:

```
#include <SoftwareSerial.h>'
SoftwareSerial mySerial(2, 3);
String inputS = "";
boolean stringComplete = false;
int i = 0;
bool b= false;

void setup() {
  mySerial.begin(9600);//Using SoftwareSerial Port
  Serial.begin(9600);
  pinMode(8, OUTPUT);//DE/RE Controling pin of RS-485
  digitalWrite(8, HIGH);//DE/RE=HIGH Transmit Enabled M1
}

void loop() {
  mySerial.println("MEGA:Hi");
  Serial.println("Hi Sent");
  digitalWrite(8, LOW);
  CheckAndReceive();
  if(stringComplete)
  {
  stringComplete = false;
  inputS.trim();
  Serial.print(inputS);
  Serial.println(": " + String(i++));
  inputS = "";
  }
  digitalWrite(8, HIGH);
    delay(1000);
}

void CheckAndReceive()
{
  while (mySerial.available()) {
    // get the new byte:
    char inChar = (char)mySerial.read();
    // add it to the inputString:
    inputS += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

```

This code is supposed to send a string to UNO and listen to it.

**UPDATE:** UNO cannot send data to MEGA at all. I think there is a problem with my UNO

# Answer
You have forgotten to add `mySerial.flush()`.

`mySerial.flush()` waits for the transmission of outgoing serial data to complete.

Add it right after you have sent the data and want to change the DE pin status.
> 3 votes

---
Tags: arduino-uno, arduino-mega, communication, rs485
---


title: Transmit data to long distance (120m)

text:
# Question
Title: Transmit data to long distance (120m)
I want to transmit data from multiple sensors to an Arduino and distance would be approximately 120 meters.

What protocol or configuration should I use?

Actually I am trying to read values from 5 temperature sensors located in 5 different spots of warehouse. I want to read them and trigger some relay based on the values.

I thought about I2C but I have read somewhere that its not built for long distances. Also thought about RS-485, but I don't know if that supports bus (connect all sensors to same line).

Which solution do you suggest?

# Answer
> 1 votes
While thinking about RS-485, did you read about it? It is a bus. It is designed for long distances.

# Answer
> 0 votes
I2C is not built for long distances (max. some meters) But you can make it via RS485, But you will need to add termination resistors to each end.

---
Tags: i2c, rs485
---


# Question
Title: Arduino not working on external power supply
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 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?

# Answer
> 1 votes
By shorting 5V to GND you have blown the 5V regulator on the board. Buy a new board unless you like reworking SMD components.

# Answer
> 2 votes
You probably have shorted 5V to the Ground and it broke the voltage regulator on the Arduino. You should by a new one. Original one have more security than non genuine and they are not expensive.

---
Tags: power
---


# Question
Title: The code is showing a error that "ledpin2 is not declared in the scope"
```
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);
}

```

# Answer
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.
> 4 votes

# Answer
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()`.

```
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);
}

```
> 1 votes

---
Tags: compilation-errors
---


title: How to set PID parameter Kp, Ki and Kd?

text:
# Question
Title: How to set PID parameter Kp, Ki and Kd?
Right now, I'm working with Peltier module using PID algorithm. I search out on the Internet about this and so I found that there are three parameters Kp, Ki and Kd. And everyone uses the different value for that. So, they actually calibrate that value but I don't understand how?

I just use default value like Kp = 2, Ki = 5 and Kd = 1.

And here I take Input as Temperature. My normal temperature is around 25. And now I set my setpoint 20. So, according to the PID algorithm temperature must be reduced to around 20. But still, no change in temperature and my PWM is still 0.

Below is my code:

```
#include <PID_v1.h>
#include "Adafruit_MAX31855.h"

int thermoDO = 3;
int thermoCS = 4;
int thermoCLK = 5;
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);

#define PIN_OUTPUT 6

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp = 2, Ki = 5, Kd = 1;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

int IN1 = 8;
int IN2 = 9;

void setup()
{
  Serial.begin(9600);

  //initialize the variables we're linked to
  Input = thermocouple.readCelsius();
  Setpoint = 20;

  //turn the PID on
  myPID.SetMode(AUTOMATIC);

  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
}

void loop()
{
  Input = thermocouple.readCelsius();
  myPID.Compute();
  analogWrite(PIN_OUTPUT, Output);

  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);

  Serial.print("Setpoint: ");
  Serial.print(Setpoint);
  Serial.print("\t");
  Serial.print("Input: ");
  Serial.print(Input);
  Serial.print("\t");
  Serial.print("Output: ");
  Serial.print(Output);
  Serial.print("\t");
  Serial.print("Kp: ");
  Serial.print(myPID.GetKp());
  Serial.print("\t");
  Serial.print("Ki: ");
  Serial.print(myPID.GetKi());
  Serial.print("\t");
  Serial.print("Kd: ");
  Serial.print(myPID.GetKd());
  Serial.print("\n");
}

```

And my output is like:

```
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 24.75    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.00    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.50    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00
Setpoint: 20.00 Input: 25.25    Output: 0.00    Kp: 2.00    Ki: 5.00    Kd: 1.00

```

Now here I use MAX31855 module for measuring the temperature which takes as Input here.

**MAX31855 Module:**

I think that may be my Kp, Ki and Kd are not perfect for my system. So, maybe this cause problem means not the proper value of Kp, Ki, and Kd. Can anyone give some suggestion how to set this value of Kp, Ki, and Kd? Or there is something else which caused the problem for that. Suggest me.

And here I'm using DC motor driver(20A) for driving the Peltier Module.

# Answer
> 5 votes
PID algorithms basically change the output to approach the setpoint. Now in your case you have a setpoint of 20 and an input of 24.5. Thus the algorithm thinks it needs to turn the output off so it can "cool down". This would work for a heater.

However since your output is a cooler you need to specify "REVERSE" rather than "DIRECT". This tells the PID module that the output needs to be higher if the input is higher than the setpoint.

---
Tags: arduino-uno, peltier
---


# Question
Title: Can I improve this code (replacing delays with something else)?
Building upon my previously solved question 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:

```
#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);
  }
}

```

# Answer
> 2 votes
You can use millis() to get a timer:
millis() 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%10=9 because10/10 = 1 and the rest is 9
        //you have wait 100 millisecond. When millis()%100 == 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()%100 = 0){
        LED1Stat = !LED1Stat;
        digitalWrite(LED1, LED1Stat);
    }
    if(millis()%250 = 0){
        LED2Stat = !LLED2Stat;
        digitalWrite(LED2, LED2Stat);
    }
    if(millis()%500 = 0){
        LED3Stat = !LED3Stat;
        digitalWrite(LED3, LED3Stat);
    }
    if(millis()%1000 = 0){
        LED4Stat = !LED4Stat;
        digitalWrite(LED4, LED4Stat);
    }
}

```

\[EDIT\]

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

}

```

# Answer
> 0 votes
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.

# Answer
> 0 votes
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.

---
Tags: programming
---


# Question
Title: Arduino Uno Keeps Resetting (Power issue)
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.

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!

# Answer
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.
> 2 votes

---
Tags: arduino-uno
---


title: Adafruit Huzzah and SD card breakout

text:
# Question
Title: Adafruit Huzzah and SD card breakout
I have an Adafruit MicroSD card breakout board and an Adafruit Feather HUZZAH with ESP8266 WiFi I wired that up according to this link's last picture.
The code I am using:

```
#include <SPI.h>
#include <SD.h>
...
const int chipSelect = 15;
...
Serial.print("Initializing SD card...");
pinMode(SS, OUTPUT);

if (!SD.begin(chipSelect)) {
     Serial.println("initialization failed!");
     return;
 }
Serial.println("initialization done.");
...

```

I always get the message "initialization failed", I also tried to format my SD card to be sure to have fat32 file system on it, but had no success with that.
What can I do to debug this error further?

TIA

# Answer
From experience, I know the following

* Using two SPI devices sometimes does not work, especially with fake SD breakout cards. Not sure about an Adafruit, but try to use only one SPI device at the same time (to check if it works better). For my project (initial setup), I had to use a SD logger extension board instead.
* Sometimes it depends on the SD card which will work. Try to use older non SDHC/XDHC cards (smaller storage normally).
* Use the most simple (and preferably example circuit) to test each component separately (thus your SD breakout card) before adding others (like the WIFI component). This rules out there is no problem with other components working at the same time.
> 1 votes

---
Tags: esp8266, sd-card
---


# Question
Title: Getting my keypad to reset when wrong password is entered
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);
  }
}

```

# Answer
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.
> 1 votes

# Answer
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.
> 0 votes

---
Tags: arduino-mega
---


# Question
Title: I2C LCD Serial Interface Board not displaying text
The code dont gives error, but not displays "Hello World"

```
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  // initialize the LCD
  lcd.begin();
  // Turn on the blacklight and print a message.
  lcd.backlight();
  lcd.print("Hello, world!");
}

void loop() {
}

```

# Answer
This can be due a lot of reasons, among:

Most common:

* Backlight is set too low (there should be a small dial)
* Circuit problem (recheck), and post it.
* The I2C address is wrong, there are sketches to check it.

Less common:

* Broken LCD
* Broken Arduino
* No power on Arduino (check LED)
> 3 votes

---
Tags: arduino-uno, i2c, lcd
---


# Question
Title: Can this work as a waterproofing method?
Im making my garden automated with temperature, humidity and soil temperature sensors. I want to be able to connect my Arduino Uno to a solar panel and keep it outside at all times. I dont want to have to remove it to water the plants. Could I cover it in clear nail polish to water proof it?

# Answer
Nail polish would work in general as a fair **conformal coating**. However, conformal coatings are not generally intended as waterproofing, but moisture or humidity resistance.

If you product is going to be regularly submerged or deluged with water, you are better off using a waterproof enclosure with a good watertight gland around the cable entrance.
> 3 votes

---
Tags: arduino-uno
---


# Question
Title: Lowest voltage applicable on AREF pin on Uno and Mega
I need to measure an Analog signal in the range of 5-30 mV.

Naturally, using the internal default 5V reference leads to very poor measurement resolution. I would like to use the capability to use an external reference voltage of 50mV on the AREF pin (using an Agilent precision power supply)

However, when I tried this in the lab, I noticed something strange. The ADC readout on the channel remained stuck at 1023. If I used anything above 0.5V on the AREF pin, the readout on the ADC is correct, and the counts reliably go up and down when I ramp up and down the Analog input accordingly.

Any idea how to resolve my issue?

# Answer
> 4 votes
According to the datasheet (page 375) the minimum voltage you are allowed to have as a reference voltage for the ADC is 1V.

# Answer
> 0 votes
In the Arduino Mega it's possible to use differential mode between two analog pins with `10x` gain (or `200x`). But, the resolution is halved (`-512` ... `511`) as it's possible to measure negative difference. But with some precision voltage reference switching and `200x` gain you might be able to archieve some precision.

The downside is those `ADC` channels are not supported by `analogRead`, you have to do it directly by setting `ADMUX` register (or `ADMUX` and `ADCSRB`) to desired differential channel with gain.

```
byte backup = ADMUX; // store the arduino settings
ADMUX = _BV(REFS1) | _BV(MUX3) | _BV(MUX0); // internal 1.1V reference, differential: ADC1+ ADC0-, gain: 10x

// there should be some delay to stabilize the voltage reference (if another one was selected)
// but it's possible to preset it by  analogReference(INTERNAL1V1); in the setup() so no delay will be needed

ADCSRA |= _BV(ADSC);  // start conversion

while ((ADCSRA & _BV(ADSC)) != 0);  // wait for conversion end (ADSC is cleared after the end by hardware)

int val = ADC; // read the result
ADMUX = backup; // restore original settings (from arduino)

```

In the Arduino everything else in ADC is configured and ADC is started, so just necessary changes are here. It should be working but I didn't tested it (I don't have the Arduino Mega here)

---
Tags: arduino-uno, analogread, adc, analog-sampling, analogreadresolution
---


# Question
Title: What Ohm Termination Resistor is needed for this schema ? What, Where and How?
I'm building a Master-Slave system using some arduino pro mini as slaves and a Mega 2560 as Master to communicate over RS485 config via MAX485. Since i'm newbie in RS485 i know that i need to put some termination resistor somewhere is the line but i don't know where and how, also i don't know how much ohm should it be. My Baud rate is 9600 and i'm using twisted pair cable (CAT5) and it's 120 meters long.

**UPDATE 1:** My goal is to get data from each slave time to time, every slave is connected to a temperature sensor and sends temperature value to master on demand (when master asks for it.) The master asks for temperature value from all slaves separately (of course!) and repeatedly every 500 ms. First it asks slave 1 to send data and then slave 1 sends data to master, then master asks slave 2 to send data and slave 2 sends data to master and so on. after 500 ms, it does this again.

**UPDATE 2:**

Master side code (Mega 2560):

```
#include <AltSoftSerial.h>
#define DE 2 //RS485 Data enable pin. HIGH=Transmit, LOW=Receive
String inputS = "";
boolean stringComplete = false;
AltSoftSerial altSerial;

void setup() {
 altSerial.begin(9600);
 Serial.begin(9600);
 pinMode(DE, OUTPUT);
}

void loop() {
 digitalWrite(DE, HIGH); //Transmit
 altSerial.println("MEGA:ProMini1");
 altSerial.flush();
 digitalWrite(DE, LOW); //Receive
 CheckAndReceiveFromMax(); //Check if data received
 if(stringComplete){
   inputS.trim();
   if(inputS.equals("ProMini1:ACK"))
    Serial.println("MEGA: ProMini1 Acknowledged: " + inputS);
   else
    Serial.println("MEGA: Not valid On ProMini1: " + inputS);
   stringComplete = false;
   inputS = "";
 }
delay(100);
digitalWrite(DE, HIGH); //Transmit
altSerial.println("MEGA:ProMini2");
altSerial.flush();
digitalWrite(DE, LOW); //Receive
CheckAndReceiveFromMax();
if(stringComplete){
  inputS.trim();
  if(inputS.equals("ProMini2:ACK"))
    Serial.println("MEGA: ProMini2 Acknowleged: " + inputS);
  else
    Serial.println("MEGA: Not valid On ProMini2: " + inputS);
  stringComplete = false;
  inputS = "";
}
delay(500);
}

void CheckAndReceiveFromMax()
{
 while (altSerial.available()) {
 char inChar = (char)altSerial.read();
 inputS1 += inChar;
 if (inChar == '\n')
  stringComplete1 = true;
 }
}

```

Slave side code (Pro Mini1):

```
#include <AltSoftSerial.h>
#define DE 7
String inputS = "";
boolean stringComplete = false;
AltSoftSerial altSerial;

void setup() {
 altSerial.begin(9600);
 Serial.begin(9600);
 pinMode(DE, OUTPUT);
}

void loop() {
 digitalWrite(DE, LOW); //Receive
 CheckAndReceiveFromMax(); //Check if data received
 if(stringComplete){
  Serial.print("String received: ");
  inputS.trim();
  Serial.println(inputS);
  if(inputS.equals("MEGA:ProMini1")){
   Serial.println("ProMini1: Mega called me!");
   digitalWrite(DE, HIGH); //Transmit
   altSerial.println("ProMini1:ACK");
   altSerial.flush();
   digitalWrite(DE, LOW);
  }
 stringComplete = false;
 inputS = "";
 }
}

void CheckAndReceiveFromMax()
{
 while (altSerial.available()) {
 char inChar = (char)altSerial.read();
 inputS += inChar;
 if (inChar == '\n')
  stringComplete1 = true;
 }
}

```

And the same code for ProMini2, ProMini3 and so on.

**OUTPUTS:** When master calls ProMini1, the ProMini2 answers, and when master calls ProMini2, ProMini1 aswers. Also, received data is not always in correct format.

Server Serial Monitor:

```
 MEGA: Not valid On ProMini1:  roMini1:ACK
  :
MEGA: Not valid On ProMini2: ProMini1:ACK
MEGA: Not valid On ProMini1:  roMini1:ACK

MEGA: Not valid On ProMini2: ProMini1:ACK

MEGA: Not valid On ProMini2:  roMini1:ACK

```

. . .

# Answer
For low data speeds, like 9600bps, termination is usually not necessary.
> 4 votes

# Answer
try 120ohm carbon resistor, not wirewound, at each end of the line ( two resistors in total)
> 2 votes

---
Tags: rs485
---