#include <Arduino.h>
byte pin[] = {5, 18, 19, 3, 1, 22, 23, 21}; // a, b, c, d, e, f, g, dp
const int button_up = 26;
const int button_down = 12;
int count_index = 0;
const byte count[10] = {
// ma du lieu cho led 7 doan
// dpGFEDCBA
B01000000, // 0
B11111001, // 1
B00100100, // 2
B10110000, // 3
B00011001, // 4
B10010010, // 5
B00000010, // 6
B11111000, // 7
B00000000, // 8
B10010000, // 9
};
void sevenSeg(byte Bit) {
for(int i = 0; i < 8; i++) {
digitalWrite(pin[i], bitRead(Bit, i));
}
}
void IRAM_ATTR up_count_index() {
if (count_index < 9) {
count_index++;
}
}
void IRAM_ATTR down_count_index() {
if (count_index > 0) {
count_index--;
}
}
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(pin[i], OUTPUT);
}
pinMode(button_up, INPUT_PULLUP);
pinMode(button_down, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_up), up_count_index, FALLING);
attachInterrupt(digitalPinToInterrupt(button_down), down_count_index, FALLING);
}
void loop() {
sevenSeg(count[count_index]);
delay(100); // Delay để giảm tần suất cập nhật và tăng ổn định
}