Last active
August 27, 2015 14:52
-
-
Save jossef/d7146f3e4eb88f189f44 to your computer and use it in GitHub Desktop.
Arduino 7seg 8 digits countdown
This file contains 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 "LedControl.h" | |
LedControl lc = LedControl(7, 6, 5, 1); | |
void setup() { | |
lc.shutdown(0, false); | |
lc.clearDisplay(0); | |
lc.setIntensity(0, 15); | |
} | |
void printDashes() { | |
lc.setChar(0, 0, '-', false); | |
lc.setChar(0, 1, '-', false); | |
lc.setChar(0, 2, '-', false); | |
lc.setChar(0, 3, '-', false); | |
lc.setChar(0, 4, '-', false); | |
lc.setChar(0, 5, '-', false); | |
lc.setChar(0, 6, '-', false); | |
lc.setChar(0, 7, '-', false); | |
} | |
void blink(int times) | |
{ | |
for (int i = 0; i < times; i++) { | |
lc.setScanLimit(0, 7); | |
lc.clearDisplay(0); | |
printDashes(); | |
delay(150); | |
lc.clearDisplay(0); | |
lc.setScanLimit(0, 0); | |
delay(150); | |
} | |
} | |
void countdown(int counter) | |
{ | |
while (counter >= 0) | |
{ | |
int maxDigit = 0; | |
int n = counter; | |
for (int i = 0; i < 8; i++) { | |
int digit = n % 10; | |
n = n / 10; | |
lc.setDigit(0, i, digit, false); | |
if (digit) | |
{ | |
maxDigit = i; | |
} | |
} | |
lc.setScanLimit(0, maxDigit); | |
delay(900); | |
lc.clearDisplay(0); | |
delay(100); | |
counter--; | |
} | |
} | |
int counter = 0; | |
void loop() { | |
blink(3); | |
delay(500); | |
countdown(9); | |
delay(500); | |
//lc.setDigit(0, 0, 1, false); | |
//lc.setIntensity(0, 1); | |
//lc.setScanLimit(0,8); | |
///delay(1000); | |
lc.clearDisplay(0); | |
delay(1000); | |
counter++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment