Yes exactly that and I've re-written the code:
// Arduino digital pins used to light up
// corresponding segments on the LED display
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define F 7
#define G 8
#define DP 9
#define SENSOR 12 // Sensor connected to pin 12
int count = 0; // current display count
const byte numbers[10] = {
0b1000000,
0b1111001,
0b0100100,
0b0110000,
0b0011001,
0b0010010,
0b0000010,
0b1111000,
0b0000000,
0b0010000
};
void setup() {
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(7, OUTPUT);
pinMode(G, OUTPUT);
pinMode(SENSOR, INPUT);
lightSegments(0b1000000);
}
void loop() {
int val = digitalRead(SENSOR);
if (val == LOW) {
count++;
if (count == 10) count = 0;
delay(500);
lightSegments(numbers[count]);
}
}
void lightSegments(byte number) {
for (int i = 0; i < 7; i++) {
int bit = bitRead(number, i);
// segments connected to Arduino pins 2-8
digitalWrite(i+2, bit);
}
}
This code doesn't interfere with the 7-segment and is very reliable compared to my last attempts.
Thanks for reply :]