Created
July 30, 2020 17:36
-
-
Save agmangas/66e4be54e00c3430a0f424433d9f2a00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
#include <Arduino.h> | |
#include <Automaton.h> | |
const uint16_t LED_NUM_01 = 30; | |
const uint16_t LED_PIN_01 = 7; | |
const uint16_t LED_NUM_02 = 30; | |
const uint16_t LED_PIN_02 = 8; | |
const uint8_t LED_BRIGHTNESS = 180; | |
Adafruit_NeoPixel ledOne = Adafruit_NeoPixel( | |
LED_NUM_01, | |
LED_PIN_01, | |
NEO_GRB + NEO_KHZ800); | |
Adafruit_NeoPixel ledTwo = Adafruit_NeoPixel( | |
LED_NUM_02, | |
LED_PIN_02, | |
NEO_GRB + NEO_KHZ800); | |
Atm_timer timerLedOne; | |
Atm_timer timerLedTwo; | |
const uint32_t LED_ONE_TIMER_MS = 50; | |
const uint32_t LED_TWO_TIMER_MS = 80; | |
const uint16_t LED_ONE_BLOB_SIZE = 5; | |
const uint32_t LED_ONE_COLOR = Adafruit_NeoPixel::Color(255, 0, 0); | |
uint16_t ledOnePixel = 0; | |
const int LED_TWO_STEP = 10; | |
uint16_t ledTwoColor = 0; | |
void onLedOneTimer(int idx, int v, int up) | |
{ | |
ledOne.clear(); | |
uint16_t pixelEnd = ledOnePixel + LED_ONE_BLOB_SIZE; | |
int pixelLimit = min(pixelEnd, ledOne.numPixels()); | |
for (int i = ledOnePixel; i < pixelLimit; i++) { | |
ledOne.setPixelColor(i, LED_ONE_COLOR); | |
} | |
if (pixelEnd > ledOne.numPixels()) { | |
int pixelRemainder = pixelEnd - ledOne.numPixels(); | |
for (int i = 0; i < pixelRemainder; i++) { | |
ledOne.setPixelColor(i, LED_ONE_COLOR); | |
} | |
} | |
ledOne.show(); | |
ledOnePixel++; | |
ledOnePixel = ledOnePixel >= ledOne.numPixels() ? 0 : ledOnePixel; | |
} | |
void onLedTwoTimer(int idx, int v, int up) | |
{ | |
const int maxColor = 255; | |
uint32_t color = Adafruit_NeoPixel::Color(0, ledTwoColor, 0); | |
ledTwo.clear(); | |
ledTwo.fill(color); | |
ledTwo.show(); | |
ledTwoColor = ledTwoColor + LED_TWO_STEP; | |
ledTwoColor = ledTwoColor >= maxColor ? 0 : ledTwoColor; | |
} | |
void initLeds() | |
{ | |
ledOne.begin(); | |
ledOne.setBrightness(LED_BRIGHTNESS); | |
ledOne.show(); | |
ledOne.clear(); | |
ledTwo.begin(); | |
ledTwo.setBrightness(LED_BRIGHTNESS); | |
ledTwo.show(); | |
ledTwo.clear(); | |
} | |
void initLedTimers() | |
{ | |
timerLedOne | |
.begin(LED_ONE_TIMER_MS) | |
.repeat(-1) | |
.onTimer(onLedOneTimer) | |
.start(); | |
timerLedTwo | |
.begin(LED_TWO_TIMER_MS) | |
.repeat(-1) | |
.onTimer(onLedTwoTimer) | |
.start(); | |
} | |
void setup() | |
{ | |
initLeds(); | |
initLedTimers(); | |
} | |
void loop() | |
{ | |
automaton.run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment