Finish week5 report
This commit is contained in:
@@ -36,27 +36,27 @@ int get_mode() {
|
||||
void show(byte digits[4]) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
digitalWrite(LATCH, LOW);
|
||||
shiftOut(DATA, CLK, MSBFIRST, ~digits[i]);
|
||||
shiftOut(DATA, CLK, MSBFIRST, ~digits[i]); // 低態觸發
|
||||
digitalWrite(LATCH, HIGH);
|
||||
digitalWrite(scan[3 - i], LOW);
|
||||
digitalWrite(scan[3 - i], LOW); // 點亮一毫秒
|
||||
delay(1);
|
||||
digitalWrite(scan[3 - i], HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
void mode_display() {
|
||||
static byte digits[4];
|
||||
static byte p = 0;
|
||||
static byte digits[4]; // 所有數字的狀態
|
||||
static byte p = 0; // 現在要改變的數字
|
||||
static unsigned long checkpoint = 0;
|
||||
show(digits);
|
||||
if (millis() - checkpoint > 200) {
|
||||
if (p == 4) {
|
||||
// all the numbers are turned on, reset
|
||||
// 所有 LED 皆點亮,重設所有值
|
||||
p = 0;
|
||||
for (int i = 0; i < 4; i++) digits[i] = 0;
|
||||
}
|
||||
digits[p] <<= 1;
|
||||
digits[p] += 1;
|
||||
digits[p] <<= 1; // 向左移位
|
||||
digits[p] += 1; // 補一
|
||||
if (digits[p] == 0xFF) {
|
||||
// if current digit is full, change to the next one
|
||||
p++;
|
||||
|
||||
Reference in New Issue
Block a user