hi guys
i added switch arduino doesnt matter if switch on or off seems code maybe getting stuck in while loop , not carrying on rest of loop.
could please point out im doing wrong ive checked switch multimeter , correct think code.
another question how important resistor on switch, know safety not accidentally burn board else?
thanks mathys
i added switch arduino doesnt matter if switch on or off seems code maybe getting stuck in while loop , not carrying on rest of loop.
could please point out im doing wrong ive checked switch multimeter , correct think code.
another question how important resistor on switch, know safety not accidentally burn board else?
code: [select]
#include <virtualwire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
#define ultratrig 5
char *msg1 = "c",*msg2 = "e",*msg3 = "s";
int timer = 200,timer2=150;
int button=7;
int buttonstate;
void setup()
{
pinmode(ultratrig,output);
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_tx_pin(3);
pinmode(button,input);
}
void loop()
{
buttonstate = digitalread(button);
if (buttonstate == high){ //stop follow button
digitalwrite(13, true);vw_send((uint8_t *)msg3, strlen(msg3));vw_wait_tx();digitalwrite(13, false);
while (buttonstate == high){
//must add remote controll here
if (buttonstate == low){
break;
}
}
}
digitalwrite(13, true);vw_send((uint8_t *)msg1, strlen(msg1));vw_wait_tx();digitalwrite(13, false);
digitalwrite(ultratrig,low);
delaymicroseconds(timer);
digitalwrite(ultratrig,high);delaymicroseconds(10);digitalwrite(ultratrig,low);
delay(timer2);
digitalwrite(13, true);vw_send((uint8_t *)msg2, strlen(msg2));vw_wait_tx();digitalwrite(13, false);
digitalwrite(ultratrig,low);
delaymicroseconds(timer);
digitalwrite(ultratrig,high);delaymicroseconds(10);digitalwrite(ultratrig,low);
delay(200);//delay before next loop
}
thanks mathys
you're not reading button anymore inside while loop ...
how ever not going high once it's in there?
how ever not going high once it's in there?
Arduino Forum > Using Arduino > Project Guidance > Toggle switch help
arduino
Comments
Post a Comment