#include <Adafruit_NeoPixel.h>
/*
Max Korrad Team
https://www.facebook.com/groups/883620498953478
*/
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);
int incomingNumber; // numero trasmesso
char Data[8]; // buffer per la stringa trasmessa
int i;
void setup()
{ Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
int state=0,y;
unsigned long int color;
char empty;
void loop() {
switch(state)
{ case 0:
Serial.println("Inserisci un numero fra 1 e 360");
while (Serial.available() == 0) { } // Wait for user input
incomingNumber = Serial.parseInt();
empty= Serial.read();
if (incomingNumber > 0 && incomingNumber <=360) state=2;
break;
case 1: // debug
Serial.println(incomingNumber);
state=2;
break;
case 2:
y = map(incomingNumber, 0, 360, 0, 16);
color=strip.Color(255, 0, 0);
for(uint16_t i=0; i<=y; i++) {
strip.setPixelColor(i,color);
strip.show();
delay(100);
}
delay(500);
color=strip.Color(0, 0, 0);
for(uint16_t i=y; i>0; i--) {
strip.setPixelColor(i,color);
strip.show();
delay(100);
}
strip.setPixelColor(0, color);
strip.show();
state=0;
break;
default:
Serial.println("Error");
state=0;
break;
}
}