What the circuit and code does:
-Allows the user to choose an led
-Allows the user to conform the led they want, and light it up permanently (will never turn off)
Notes:
-When the user is choosing an led, the previous one will turn off to show which led you can choose.
Problem: When choosing an LED (with the 1st button, on the far left), the LED turns on, with the previous one turning off, which is what is supposed to happen. However, when SELECTING an Led and then continuing to choose them, the last led on pin 10 does not function properly.
- Pin 10 Led (bottom right), when pressed to confirm, it will go on, but then go off right after even when it is selected to be permanent
Below is the image, and code:
int led = 2; //led / digital pin that is active
bool permanentState[12]; //array to store permanent led's / digital pins
void pinset() { //setting each digital pin as an output
for (int b = 2; b !=11; b++) {
pinMode(b, OUTPUT);}
}
void clickled(){ //stores the current led / pin permanently
if (analogRead(A5) == 500) {
permanentState[led] = true;}
}
void choose_select_pin() {
clickled();
if (analogRead(A5) == 755) { //value to do the folling commands underneath
while (true) {
int j = led - 1;
if (!permanentState[led]) {//does not turn off the permanent leds
digitalWrite(j, LOW); //turns off the previous led (not permanent ones)
}
digitalWrite(led, HIGH); //turns on the LED based on the led variable
Serial.println(led);
Serial.print("Pin Active:");
if (led == 11) {
// Turn off the LED at pin 10 if it's not permanent
if (!permanentState[10]) {
digitalWrite(10, LOW);
}
led = 1; // goes back to the 1st digital pin
}
delay(400);
if (led != 11) {
led++; //increases the led variable if the digital pin is from 1 - 10
}
if (analogRead(A5) != 755) {
break; //breaks the while loop if the left button is not being pressed
}
}}}
void setup() {
Serial.begin(9600); // Initialize serial communication
pinset();
}
void loop() {
Serial.print("voltage signal: ");
Serial.println(analogRead(A5));
choose_select_pin();
delay(2000);
}
Image to show circuit
