Week 5
This commit is contained in:
42
week5-4/week5-4.ino
Normal file
42
week5-4/week5-4.ino
Normal file
@@ -0,0 +1,42 @@
|
||||
const unsigned int scan[] = {5, 6, 7, 8};
|
||||
#define DATA 10
|
||||
#define LATCH 11
|
||||
#define CLK 12
|
||||
|
||||
byte numbers[] = {
|
||||
0xC0, 0xF9, 0xA4, 0xB0, 0x99,
|
||||
0x92, 0x82, 0xF8, 0x80, 0x90
|
||||
};
|
||||
|
||||
void setup() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
pinMode(scan[i], OUTPUT);
|
||||
digitalWrite(scan[i], HIGH);
|
||||
}
|
||||
pinMode(DATA, OUTPUT);
|
||||
pinMode(LATCH, OUTPUT);
|
||||
pinMode(CLK, OUTPUT);
|
||||
}
|
||||
|
||||
void show(int digits[10], int shift) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
digitalWrite(LATCH, LOW);
|
||||
shiftOut(DATA, CLK, MSBFIRST, numbers[digits[(shift + i) % 10]]);
|
||||
digitalWrite(LATCH, HIGH);
|
||||
digitalWrite(scan[3-i], LOW);
|
||||
delay(1);
|
||||
digitalWrite(scan[3-i], HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static unsigned long checkpoint = 0;
|
||||
static int digits[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
static int count = 0;
|
||||
show(digits, count);
|
||||
if (millis() - checkpoint > 500) {
|
||||
count--;
|
||||
if (count < 0) count = 9;
|
||||
checkpoint = millis();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user