#define SEG_COUNT 7
const int firstSeg = 2;
const byte numberSegments[16] = {
0b11000000, //0
0b11111001, //1
0b10100100, //2
0b10110000, //3
0b10011001, //4
0b10010010, //5
0b10000010, //6
0b11111000, //7
0b10000000, //8
0b10010000, //9
0b00001000, //A
0b00000011, //b
0b01000110, //C
0b00100001, //d
0b00000110, //E
0b00001110, //F
};
int lastButton = LOW;
int curButton = LOW;
const int button = 12;
int debounce (int last)
{
int current = digitalRead(button);
if(last != current)
{
delay(5);
current = digitalRead(button);
}
return current;
}
void Clicked(int &count){
curButton = debounce (lastButton);
if(lastButton == HIGH && curButton == LOW)
{
Serial.println(count);
count++;
if(count == 16){
count = 0;
}
}
lastButton = curButton;
}
void setup() {
Serial.begin(9600);
for (int i = 0; i < SEG_COUNT; ++i){
pinMode(i + firstSeg, OUTPUT);
}
pinMode(button, INPUT);
digitalWrite(button, HIGH);
}
void loop() {
int mask;
boolean enableSegment;
static int count = 0;
Clicked(count);
mask = numberSegments[count];
for (int i = 0; i < SEG_COUNT; i++)
{
enableSegment = bitRead(mask, i);
digitalWrite(i + firstSeg, enableSegment);
}
}