non blocking led animation

bluepill
JbLb 6 years ago
parent 588212519f
commit 4fb41ef464

@ -28,7 +28,7 @@ Nunchuk nchuk(Wire2);
// ########################## DEFINES ##########################
#define LED_BUILTIN PC13
#define TIME_SEND 20 // [ms] poolling time interval
#define TIME_SEND 100 // [ms] time interval
#define HOVER_SERIAL_BAUD 38400 // [-] Baud rate for HoverSerial (used to communicate with the hoverboard)
#define START_FRAME 0xAAAA // [-] Start frme definition for reliable serial communication
#define SCREEN_WIDTH 128 // OLED display width, in pixels
@ -109,6 +109,7 @@ void setup()
Serial1.begin(HOVER_SERIAL_BAUD);
strip.begin(); // INITIALIZE NeoPixel strip object
strip.clear();
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
@ -280,13 +281,29 @@ void Nunchuk_control()
// ########################## LOOP ##########################
unsigned long iTimeSend = 0;
int idx_led = 0;
void loop()
{
unsigned long timeNow = millis();
// Blink the LED
digitalWrite(LED_BUILTIN, (timeNow % 2000) < 1000);
Receive();
Nunchuk_control();
Serial.println(timeNow);
if (iTimeSend > timeNow)
return;
iTimeSend = timeNow + TIME_SEND;
strip.clear();
strip.setPixelColor(idx_led, strip.Color(128, 0, 0));
if (idx_led < strip.numPixels() -1 )
{
idx_led++;
}
else
{
idx_led = 0;
}
strip.show();
}

Loading…
Cancel
Save