#ifdef __AVR__
#include
#endif
static const int PIN = 3;
static const int NUMPIXELS = 2;
int incomingByte;
char incomingLetter;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
unsigned long interval = 10000;
unsigned long previousMillis = 0;
void setup() {
pixels.begin();
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.show();
}
void loop() {
unsigned long currentMillis = millis();
if (Serial.available() > 0) {
incomingByte = Serial.read();
incomingLetter = (char) incomingByte;
if (incomingLetter == ‘S’) {
while(currentMillis – previousMillis < interval) {
currentMillis = millis();
}
previousMillis = currentMillis;
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
pixels.show();
}
else if (incomingLetter == ‘B’) {
while(currentMillis – previousMillis < interval){
pixels.setPixelColor(1, pixels.Color(0, 255, 0));
pixels.show();
currentMillis = millis();
}
previousMillis = currentMillis;
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.show();
}
else {
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.show();
}
}
}