Hi,
First off, it's the first time i managed to tinker with an arduino and it's coding language. I'm trying to make a simple program to use in my classes. (Still studying to be a teacher.)
I'm used to programming in LAD and GRAFCET, so i'll explain what the program needs to run through in a similar way.
The project is a SAFE for valuable objects. It can only open when 3 conditions are met, which are in fact a button switch, a ON/OFF-Switch, and possibly a LDR-switch (still considering the last one, since it's analog).
if the button switch AND the ON/OFF-Switch and the LDR-switch are HIGH
LED 1 (Green one) burns
Servo turns 90° to open the door
if the button switch AND the ON/OFF-Switch and the LDR-switch are LOW
Servo turns 90° to close the door OR if they are stil LOW, the servo does nothing and stays closed obviously.
Now i've managed to get some functions working but when i try to read multiple inputs it gives the error: 'switchState1
' is not declared
I've tried giving multiple names to it like:
switchState1
switchState2
....
void setup() {
int switchState1 = 0;
int switchState2 = 0;
int switchState3 = 0;
pinMode(2,INPUT);
//Push-button
pinMode(3,INPUT);
//LDR
pinMode(4,INPUT);
//ON/OFF SWITCH
pinMode(5,OUTPUT);
//Servo
pinMode(6,OUTPUT);
//LED RED
pinMode(7,OUTPUT);
//LED GREEN
// Toewijzen van de inputs en outputs aan pins
}
void loop() {
// put your main code here, to run repeatedly:
switchState1 = digitalRead(2);
switchState2 = digitalRead(3);
switchState3 = digitalRead(4);}
if (switchState1 == HIGH)&&(switchState2 == HIGH)&&(switchState3 == HIGH) {
digitalWrite(5,HIGH); //Servo
switchState = digitalRead(3);
digitalWrite(6,HIGH); //LED RED
switchState = digitalRead(4);
digitalWrite(7,HIGH); //LED GREEN
}
Now, i'm not asking to write the code for me (I need to be able to code it on my own, so i can learn it and furthermore translate it in simple exercises for my future classes), but i am asking someone willingly enough to point my wrongdoings out so i know where the faulty code is and whats wrong with it.
I'd be more than grateful for any help!
Thanks in advance.
Quick edit:
I'm using ARDUINO UNO
and ARDUINO IDE