Hello!
I try to make a counter up to 60 using a neopixel led ring which should actually represent seconds. I divided the counter into 5 stages (5 * 12 = 60) each with a different color of the LEDs on. This program crashes at stage 1, meaning it counts to 12 and stays that way. How should I write this program for counting to continue until 60?
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN 6
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 12
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
int s,i,j,k,l,m;
void setup() {
Serial.begin(9600);
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
for(s = 0; s < 60; s++){
if(s < 12){
for(i = 0; i < NUMPIXELS; i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(150,0,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}// 1st For
if(i==NUMPIXELS){
pixels.clear();
}
}// 1st If
else if((s > 11) && (s < 24)){
for(j = 0; j < NUMPIXELS; j++){
pixels.setPixelColor(j, pixels.Color(0,150,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}// 2st For
if(j==NUMPIXELS){
pixels.clear();
}
}// 2st If
else if((s > 23) && (s < 36)){
for(k = 0; k < NUMPIXELS; k++){
pixels.setPixelColor(k, pixels.Color(0,0,150)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}// 3st For
if(k==NUMPIXELS){
pixels.clear();
}
}// 3st If
else if((s > 35) && (s < 48)){
for(l = 0; l < NUMPIXELS; l++){
pixels.setPixelColor(l, pixels.Color(150,150,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}// 4st For
if(l==NUMPIXELS){
pixels.clear();
}
}// 4st If
else if((s > 47) && (s < 60)){
for(m = 0; m < NUMPIXELS; m++){
pixels.setPixelColor(m, pixels.Color(0,150,150)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}// 5st For
if(m==NUMPIXELS){
pixels.clear();
}
}// 5st For
if(s == 60){
pixels.setPixelColor(m, pixels.Color(150,150,150)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(1000);
}// 6st If
}// BIG For
}// loop