Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DELAY_LIST_SIZE 18U
- const uint16_t delayList[DELAY_LIST_SIZE] = {
- 100, 150, 100, 150, 100, // S
- 500,
- 400, 150, 400, 150, 400, // O
- 500,
- 100, 150, 100, 150, 100, // S
- 1500};
- void timedToggle() {
- static uint16_t msLeft = 0;
- static uint8_t currentState = 0;
- static uint8_t delayListIndex = 0;
- // Have we waited long enough?
- if (0 == msLeft) {
- // Toggle LED state
- currentState = 1 - currentState;
- digitalWrite(13, currentState);
- // Get the next wait time
- msLeft = delayList[delayListIndex];
- delayListIndex++;
- // Restart if reached the end of the list
- if (DELAY_LIST_SIZE == delayListIndex) {
- delayListIndex = 0;
- }
- } else {
- msLeft--;
- }
- }
- void setup() {
- pinMode(13, OUTPUT);
- }
- void loop() {
- static uint32_t lastMillis = 0;
- // Call the LED toggling handler every 1ms
- if (millis() != lastMillis) {
- lastMillis = millis();
- timedToggle();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement