I've written the code (below) for a sequence of events to occur based on the user "cutting the wires" to "diffuse" a "bomb". Of course this is just a special effect and not the real thing. There are several elements involved and this is just the wire cutting sequence.
I thought this would be rather simple, but I think I'm over writing the code. I'm new at this and have done all the relevant tutorials, and have tried researching for similar codes, but are not having any luck. I've changed and changed the code based on other projects but to of no avail.
I've also included the layout of the bread board layout so you can see if I've done something wrong there. (I've changed it many times as well.) I've also checked to make sure there is continuity on all the LEDs circuits.
I've figured out the "final reward", but still need to code the special effects actions, but that is later when parts arrive.
Not sure if this is relevant, but when I press the rest button on the Arduino UNO it's not flashing the TX and RX onboard LEDS like it has in the past.
Just got the beginner level starter kit this Christmas (2015) and I'm excited to get some stuff working. I'm just struggling with the code I think. I should have all the current updates to the programming.
Any help in figuring out where I'm going wrong, would be highly appreciated.
Thanks in advance!
Mark
/*Wire Cutting sequence test
Cut the right wires in the right order and you win. Cut the wrong wire and or in the wrong order,
and you lose, and the special effect activates.
LED s represent the wires. If you pull out the LEDs ("cut the wire") it opens the circuit.
Which sets off the effect. The first Green LED on the left represents the three "wrong" Wires.
All three would be wired in series and cutting any one would open the one circuit. So one LED will
work to test the code.
The next 3 Yellow LED s represent the three correct wires to cut and in the order they need to be
cut, Left to Right. The Red LED s represent the three elements of the special effects.
Their codes to be added later. These will light up if activated by cutting the wrong wires or
cutting the right ones out of order.
The last Blue LED represents the final Correct solution. It activates another effect that signals
the successful completion of test.
*/
const int wrongWire = 13; // the number of the wrong wire pin
const int firstWire = 12; // the number of the first wire pin
const int secondWire = 11; // the number of the second wire pin
const int thirdWire = 10; // the number of the third wire pin
const int smoke = 7; // the number of the smoke pin
const int light = 6; // the number of the light pin
const int sound = 5; // the number of the sound pin
const int drawer = 4; // the number of the drawer pin
int wrongWireState = HIGH;
int firstWireState = HIGH;
int secondWireState = HIGH;
int thirdWireState = HIGH;
int smokeState = LOW;
int lightState = LOW;
int soundState = LOW;
int drawerState = LOW;
void setup() {
pinMode(wrongWire, INPUT);
pinMode(firstWire, INPUT);
pinMode(secondWire, INPUT);
pinMode(thirdWire, INPUT);
pinMode(smoke, OUTPUT);
pinMode(sound, OUTPUT);
pinMode(light, OUTPUT);
pinMode(drawer, OUTPUT);
}
void loop() {{
digitalRead(wrongWire);
digitalRead(firstWire);
digitalRead(secondWire);
digitalRead(thirdWire);
digitalRead(drawer);
}
// if wrong wire is cut sets off special effects
if (wrongWire == LOW) {
digitalWrite(smoke, HIGH);
delay(500);
digitalWrite(light, HIGH);
delay(500);
digitalWrite(sound, HIGH);
}
//if wires cut in wrong order sets off special effects
if ((secondWire == LOW) && (firstWire == HIGH)){
digitalWrite(smoke, HIGH);
//delay(500);
digitalWrite(light, HIGH);
//delay(500);
digitalWrite(sound, HIGH);
}
//if wires cut in wrong order sets off special effects
if ((thirdWire == LOW) && (firstWire == HIGH) || (secondWire == HIGH)){
digitalWrite(smoke, HIGH);
//delay(500);
digitalWrite(light, HIGH);
//delay(500);
digitalWrite(sound, HIGH);
}
// all wires cut in correct order , activates effect to indicate sucessful completion
if ((thirdWire == LOW) && (firstWire == LOW) && (secondWire == LOW)){
(drawer, HIGH);
}
}
Wire_Cutting_Sequence.ino (2.73 KB)