Hi open source cronies,
I am looking for some help! I am working on a project that uses the fastled Library, with an array of 6 ws2812b strips and an uno R3.
Please bear in mind, I am very new to Arduino projects and code but I am also a very curious person, with high hopes of developing my own lighting projects. In the meantime, I am using others code as I am a visual learner, while attempting to investigate and learn as much as I can by going through project code. I am running into a bump in the road, where I cant figure something out!
what I have done thus far, is I have 4 C batteries connected to power on all 6 strips, and the ground connected to the ground on all 6 strips. I have pins 4,5,6,7,8,9 on the duino going to the digital in on each led strip as well. so far so good, but my biggest issue is, I have a lack of understanding how the buttons are connected from this code.
I know that it defines input 1 as pin13 and input 2 as pin 12, but I cant seem to figure out how to connect a button to these pins and get the desired outcome from the code as the buttons I have, seem to have 4 connectors on them.
I am wondering, if anyone has any time to help me with this, can you help review the code and maybe provide me with a pointer on how I can get the buttons connected to this and actually put the code to use with this led array?
also one other thing i dont understand is, the mention of pin3 for the ISR- does something need to be connected to pin 3 as well besides pin12 and pin 13? i appreciate any help of course- Included some of the code below right before the main iteration loop.
#include <Adafruit_NeoPixel.h>
#define COUNT 52
#define TAIL 13
#define INPUT1 13
#define INPUT2 12
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(COUNT, 4, NEO_GRB + NEO_KHZ400);
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(COUNT, 5, NEO_GRB + NEO_KHZ400);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(COUNT, 6, NEO_GRB + NEO_KHZ400);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(COUNT, 7, NEO_GRB + NEO_KHZ400);
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(COUNT, 8, NEO_GRB + NEO_KHZ400);
Adafruit_NeoPixel strip5 = Adafruit_NeoPixel(COUNT, 9, NEO_GRB + NEO_KHZ400);
volatile int mode;
volatile int erased=0;
int lastpos = 0;
int ringarray[5] = {0,0,0,0,0} ;
uint32_t ringcolor[5];
int ringdirection[5]= {0,0,0,0,0};
Adafruit_NeoPixel strips[6] = {strip0, strip1, strip2, strip3, strip4, strip5} ;
//------------------------------------------
// Setup - initialize ALL THE THINGS...
//------------------------------------------
void setup() {
// Initialize the strips...
for (int i=0; i<6; i++) {
strips[i].begin();
}
randomSeed(analogRead(0));
pinMode(INPUT1, INPUT);
pinMode(INPUT2, INPUT);
digitalWrite(INPUT1, HIGH); // turn on pullup resistors
digitalWrite(INPUT2, HIGH); // turn on pullup resistors
Serial.begin(9600);
attachInterrupt(0, userbutton, RISING);
mode=6;
}
//------------------------------------------
// userbutton - this is an ISR - Interrupt Service Routine - it's called
// whenever someone transitions int.0 RISING (see setup() for the def). On
// the Uno R3, this must be pin 3.
//------------------------------------------
void userbutton() {
// This debounce routine snarfed from http://forum.arduino.cc/index.php/topic,45000.0.html
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 200) {
mode = mode + 1;
erased=0;
if ( mode > 6 ) {
mode = 0;
}
// Conditionals based on button input...
// If button 1 is held down, go right back to idle mode
// If button 2 is held down, do ${something}
// If both buttons are held down, do the FLASH animation, then go to the sparkly.
if (digitalRead(INPUT1) == LOW && digitalRead(INPUT2) == LOW) {
mode=7;
} else {
if (digitalRead(INPUT1) == LOW && digitalRead(INPUT2) == HIGH) {
mode = 6;
}
}
// Serial.println("Reading values from INPUT1 and INPUT2....");
// Serial.println(digitalRead(INPUT1));
// Serial.println(digitalRead(INPUT2));
}
last_interrupt_time = interrupt_time;
}