hi i have made a robot car which navigates a maze by it self and also can be controlled by the phone.so without having to upload the different codes all the time i thought i will put a press switch as per this link (https://www.arduino.cc/en/Tutorial/Switch)
and try to make it so that when a button is pressed the maze solving code will work and if button not pressed the bluetooth code will work. i have written the following code
int LED = 13;
int BUTTON = 2;
void setup(){
pinMode(LED,OUTPUT);
pinMode(BUTTON,INPUT);
}
void loop(){
if(digitalRead(BUTTON) == HIGH){
digitalWrite(LED,HIGH);
}else{
digitalWrite(LED,LOW);
}
}
to test the switch function.
can someone please tell me how to use it for my car to solve the maze when button is pressed and bluetooth manual when button not pressed, Thank you
boolean doMaze = false;
void loop(){
if(digitalRead(BUTTON) == HIGH){
doMaze = !doMaze; // flip the state of your flag variable
}
if(doMaze){
// do your maze code
}
else {
// do your bluetooth code
}
}
i changed your code to this way,is it correct?
it says error compiling the whole time
btw thank you for helping
yes thats my bad,so i used the state thing and the code works now.
thank you for that
so when i power the car the blutooth thing works first properly,also when button is pressed it starts the maze thing.
thats what i expected to happen.
im really greatful for helping me to do that.