const int analogPin1 = A0;
const int analogPin2 = A1;
const int redLEDPin = 9;
const int greenLEDPin = 10;
const int buttonPin = 5;
const int buttonPin2 = 6; // New button pin
const int ledPins[] = {11, 12, 13};
int buttonState = 0;
int lastButtonState = 0;
int buttonState2 = 0; // State for the second button
int lastButtonState2 = 0; // Last state for the second button
int counter = 0;
void setup() {
pinMode(redLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
for (int i = 0; i < 3; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT); // Set the second button pin as input
Serial.begin(9600);
}
void loop() {
int analogValue1 = analogRead(analogPin1);
int analogValue2 = analogRead(analogPin2);
int scaledValue1 = map(analogValue1, 0, 1023, 0, 100);
int scaledValue2 = map(analogValue2, 0, 1023, 0, 100);
bool redLEDState = LOW;
bool greenLEDState = LOW;
if (scaledValue1 > 75 && scaledValue2 > 50) {
redLEDState = HIGH;
greenLEDState = HIGH;
} else if (scaledValue1 > 50) {
redLEDState = LOW;
greenLEDState = HIGH;
} else if (scaledValue1 > 25) {
redLEDState = HIGH;
greenLEDState = LOW;
} else {
redLEDState = LOW;
greenLEDState = LOW;
}
digitalWrite(redLEDPin, redLEDState);
digitalWrite(greenLEDPin, greenLEDState);
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2); // Read the state of the second button
if (buttonState == HIGH && lastButtonState == LOW) {
counter++;
if (counter > 7) {
counter = 0;
}
updateLEDs();
delay(50);
}
if (buttonState2 == HIGH && lastButtonState2 == LOW) { // If the second button is pressed
counter--; // Decrement the counter
if (counter < 0) {
counter = 7; // Wrap around at 7
}
updateLEDs(); // Update the LEDs
delay(50); // Debounce delay
}
lastButtonState = buttonState;
lastButtonState2 = buttonState2; // Update the last state of the second button
Serial.print("Analog Value 1 = ");
Serial.println(analogValue1);
Serial.print("Analog Value 2 = ");
Serial.println(analogValue2);
Serial.print("Analog Value 1 Scaled = ");
Serial.println(scaledValue1);
Serial.print("Analog Value 2 Scaled = ");
Serial.println(scaledValue2);
Serial.print("LED RED = ");
Serial.println(redLEDState == HIGH ? "ON" : "OFF");
Serial.print("LED GREEN = ");
Serial.println(greenLEDState == HIGH ? "ON" : "OFF");
delay(500);
}
void updateLEDs() {
for (int i = 0; i < 3; i++) {
digitalWrite(ledPins[i], (counter >> i) & 0x01);
}
}