// Define the pins for each segment (a to g) and the common cathode pin
const int segmentPins[8] = {0, 1, 2, 3, 4, 5, 6, 7};
//const int commonCathodePin = 9;
int buttonPin1= 9;
int buttonPin2= 10;
int buttonState1;
int buttonState2;
// Define the numbers to display on the seven-segment display
const byte numbers[11] = {
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11110110 // 9
};
#define ESCOLHENDO 1
#define CONOTAGEM 2
int estado = 1;
void setup() {
// Set segment pins as outputs
Serial.begin(9600);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
// Set common cathode pin as output
//pinMode(commonCathodePin, OUTPUT);
}
void loop()
{
switch (estado) {
case 1:
Serial.println("estou no estado 1");
delay(1000);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == LOW or buttonState2 == HIGH)
{
digitalWrite(buttonPin1, HIGH);
int i = 0;
displayNumber(i++);
}
else if(buttonState1 == HIGH or buttonState2 == LOW )
{
digitalWrite(buttonPin2, HIGH);
int i = 0;
displayNumber(i++);
}
break;
case 2:
Serial.println("estou no estado 2");
delay(1000);
// Count from 0 to 9
for (int i = 0; i < 10; i++)
{
displayNumber(i);
// while(1);
delay(1000); // Display each number for 1 second
// for (int j = 0; j < 8; j++) {
// digitalWrite(segmentPins[j], LOW);
//}
}
break;
}
}
// Function to display a digit on the seven-segment display
void displayNumber(int num) {
// Turn off all segments
for (int i = 0; i < 8; i++) {
digitalWrite(segmentPins[i], HIGH);
}
// Activate segments based on the number to be displayed
for (int i = 0; i < 8; i++) {
if (bitRead(numbers[num], i) == LOW) {
digitalWrite(segmentPins[7-i], LOW);
}
}
// Turn on the common cathode to display the digit
// digitalWrite(commonCathodePin, LOW);
}