// 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>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 2 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 200 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50 // Time (in milliseconds) to pause between pixels
int start_led = 0;
int stop_led = NUMPIXELS;
int color_led = 10;
int totalStopNum[20] = {};
int color[10][3] = {
{255, 0, 0},
{0, 255, 0},
{0, 0, 255},
{255, 255, 0},
{0, 255, 255},
{255, 0, 255},
{192, 192, 192},
{128, 0, 0},
{128, 128, 0},
{0, 128, 0},
};
void runningColorSetup (int start, int stop, int colorTotal){
for (int i=0;i<colorTotal;i++){
int divider = (stop-start)/colorTotal;
int stopperVal = (i+1)*divider;
totalStopNum[i] = stopperVal;
Serial.print(stopperVal);
Serial.print(", ");
}
Serial.println();
}
void runningColorLoop(int start,int stop, int colorTotal, bool reverse=false){
for(int a=0;a<colorTotal;a++){
int numTemp = totalStopNum[a];
if (reverse==false){
if (numTemp>=stop) numTemp = start;
else numTemp = totalStopNum[a]+1;
}else{
if (numTemp<=start) numTemp = stop;
else numTemp = totalStopNum[a]-1;
}
totalStopNum[a]=numTemp;
// Serial.print(numTemp);
// Serial.print(color[a][3]);
// Serial.print(", ");
int awal = totalStopNum[a];
int akhir = 1000;
if (a==(colorTotal - 1)){
akhir=totalStopNum[0];
}
else{
akhir=totalStopNum[(a+1)];
}
// Serial.print("(");Serial.print(a);Serial.print("=");Serial.print(awal);Serial.print(" ");
// Serial.print(a+1);Serial.print("=");Serial.print(akhir);Serial.print("), ");
// Serial.print(color[a][0]);Serial.print(color[a][1]);Serial.print(color[a][2]);
if (awal>akhir){
for (int b = awal; b<=stop; b++){
pixels.setPixelColor(b, pixels.Color(color[a][0], color[a][1], color[a][2]));
}
for (int c = start; c<=akhir; c++){
pixels.setPixelColor(c, pixels.Color(color[a][0], color[a][1], color[a][2]));
}
}
else{
for (int d = awal; d<=akhir; d++){
pixels.setPixelColor(d, pixels.Color(color[a][0], color[a][1], color[a][2]));
}
}
}
// Serial.println();
pixels.show();
}
void setup() {
Serial.begin(115200);
Serial.println("Hello Pico");
runningColorSetup(start_led,stop_led,color_led);
// Serial.println(sizeof(totalStopNum)/sizeof(int));
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
runningColorLoop(start_led,stop_led,color_led,true);
// Serial.println("Start");
delay(30);
// pixels.clear(); // Set all pixel colors to 'off'
// for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
// pixels.setPixelColor(i, pixels.Color(0, 150, 100));
// pixels.show(); // Send the updated pixel colors to the hardware.
// delay(DELAYVAL); // Pause before next pass through loop
// }
}