43 lines
1.3 KiB
C
43 lines
1.3 KiB
C
#ifndef _LED_H_
|
|
#define _LED_H_
|
|
|
|
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
|
|
#define LED_PIN 3
|
|
#define LED_COUNT 16
|
|
|
|
// NeoPixel brightness, 0 (min) to 255 (max)
|
|
#define BRIGHTNESS 50 // Set BRIGHTNESS to about 1/5 (max = 255)
|
|
|
|
// Declare our NeoPixel strip object:
|
|
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
|
|
|
|
unsigned long last_ledupdate=0;
|
|
#define LEDUPDATEINTERVAL 100
|
|
|
|
void init_led() {
|
|
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
|
strip.show(); // Turn OFF all pixels ASAP
|
|
strip.setBrightness(BRIGHTNESS);
|
|
}
|
|
|
|
void led_update(unsigned long loopmillis) {
|
|
if (loopmillis>last_ledupdate+LEDUPDATEINTERVAL) {
|
|
last_ledupdate=loopmillis;
|
|
uint32_t color=strip.Color(0, 0, 0, 255);
|
|
uint32_t colorOff=strip.Color(30, 0, 0, 0);
|
|
uint8_t position=(loopmillis/100)%strip.numPixels();
|
|
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
|
|
if (i==position) {
|
|
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
|
|
}else{
|
|
strip.setPixelColor(i, colorOff); // Set pixel's color (in RAM)
|
|
}
|
|
}
|
|
strip.show(); // Update strip to match
|
|
}
|
|
}
|
|
|
|
#endif |