Hi all,
First time posting and Arduino newbie. I am currently working on a project for an escape-room type puzzle where the players have to defuse a fake bomb by cutting the wires in the correct sequence.
I have been using Tinkercad to build a proof of concept but am having some issues with the code; specifically building a conditional with multiple layers. I have some programming experience with Python but I am new to Arduino’s.
/*Redpin/greenpin determines wires set to light an RGB LED \
red/green and the Stat varibales are for the wires to be cut.*/
int redPin1 = 13;
int greenPin1 = 12;
int redPin2 = 11;
int greenPin2 = 10;
int redPin3 = 9;
int greenPin3 = 8;
int redPin4 = 7;
int greenPin4 = 6;
int redPin5 = 5;
int greenPin5 = 4;
int redStat = 3;
int orangeStat = 2;
int yellowStat = 1;
/*Setting my Ins/Outs, and also setting inital lighting for my \
LED's as all red.*/
void setup()
{
pinMode(redPin1, OUTPUT);
pinMode(greenPin1, OUTPUT);
pinMode(redPin2, OUTPUT);
pinMode(greenPin2, OUTPUT);
pinMode(redPin3, OUTPUT);
pinMode(greenPin3, OUTPUT);
pinMode(redPin4, OUTPUT);
pinMode(greenPin4, OUTPUT);
pinMode(redPin5, OUTPUT);
pinMode(greenPin5, OUTPUT);
pinMode(redStat, INPUT);
pinMode(orangeStat, INPUT);
pinMode(yellowStat, INPUT);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
}
/*A function that if the incorrect wire is cut flips all lights \
to red.*/
void failWrite()
{
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
}
void loop()
{
if ((digitalRead(redStat) == LOW) && (digitalRead(orangeStat)==HIGH))
{
if (digitalRead(yellowStat)==HIGH)
{
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
}
else
{
failWrite();
}
}
if ((digitalRead(orangeStat)==LOW) && (digitalRead(redStat)==LOW))
{
if(digitalRead(yellowStat)==HIGH)
{
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
}
else
{
failWrite();
}
}
}
I have attached a graphic of my wiring as well. I know my logic is off because when the red and orange wires are cut, red goes back to red but orange stays green. I am not sure how to build a function with multiple conditionals that would satisfy my requirements (some kind of nested function maybe?) If there are any tips you can give in regards to my logic or even my wiring it would be greatly appreciated. Sorry for being a noob!