const byte SEVEN_SEG[7] = {3, 4, 5, 6, 7, 8, 9};
byte number[10][7] = {{1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 0, 0, 0, 0},
{1, 1, 0, 1, 1, 0, 1}, {1, 1, 1, 1, 0, 0, 1}, {0, 1, 1, 0, 0, 1, 1},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 0, 1, 1}};
void setup() {
for (int i = 0; i < 7; i++) {
pinMode (SEVEN_SEG[i], OUTPUT);
digitalWrite (SEVEN_SEG[i], number[1][i]);
}
}
void loop() {
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 7; y++) {
pinMode (SEVEN_SEG[y], OUTPUT);
digitalWrite (SEVEN_SEG[y], number[x][y]);
//delay(100);
}
delay(1000);
}
}
โค้ดการทดลองที่ 3.2.9
const byte SEVEN_SEG[7] = {3, 4, 5, 6, 7, 8, 9};
const byte SW = 2;
const byte s = 10;
byte number[10][7] = {{1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 0, 0, 0, 0},
{1, 1, 0, 1, 1, 0, 1}, {1, 1, 1, 1, 0, 0, 1}, {0, 1, 1, 0, 0, 1, 1},
{1, 0, 1, 1, 0, 1, 1}, {1, 0, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 0, 1, 1}
};
void setup() {
}
void loop() {
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 7; y++) {
if (digitalRead(SW) == LOW) {
pinMode (s, OUTPUT);
digitalWrite (s, HIGH);
} else {
pinMode (s, OUTPUT);
digitalWrite (s, LOW);
x=0;
y=0;
}
pinMode (s, OUTPUT);
pinMode (SEVEN_SEG[y], OUTPUT);
digitalWrite (SEVEN_SEG[y], number[x][y]);
} delay(1000);
}
}