const int btnMinus = 2;
const int btnPlus = 3;
const int data = 4;
const int latch = 5;
const int clock = 6;
const byte digits[] {
// ABCDEFGDp
// ||||||||
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11110110, // 9
B11101110, // A
B00111110, // B
B10011100, // C
B01111010, // D
B10011110, // E
B10001110, // F
};
int count;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(btnMinus, INPUT);
pinMode(btnPlus, INPUT);
pinMode(data, OUTPUT);
pinMode(latch, OUTPUT);
pinMode(clock, OUTPUT);
digitalWrite(latch, HIGH);
count = 0;
Serial.print("Count : ");
Serial.println(count);
displayCount();
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(btnMinus) == HIGH) {
if (count <= 0) {
count = 255;
} else {
count--;
}
delay(250);
displayCount();
}
if (digitalRead(btnPlus) == HIGH) {
if (count >= 255) {
count = 0;
} else {
count++;
}
delay(250);
displayCount();
}
}
void displayCount() {
Serial.print("Count : ");
Serial.println(count);
byte tens = count % 256 / 16;
byte units = count % 16;
sendCount(digits[tens], digits[units]);
}
void sendCount(byte tens, byte units) {
digitalWrite(latch, LOW);
shiftOut(data, clock, LSBFIRST, units);
shiftOut(data, clock, LSBFIRST, tens);
digitalWrite(latch, HIGH);
}