I make communication between 2 arduino via Bluetooth.
My purpose is that when I click button1 in master, slaver will do the code in my purpose. The code will stop when I click the previous button1 again.
Note: Im using bluetooth to send data when the button is pushed
Number 1 is sent when I click the button.
Here my sending code
phamb587:
Can you give me an example of code It is so general
Sincere thanks
// global variables
boolean state = FALSE;
byte buttonPushed; this is generic variable - there is really no button , but whatever your BT code passed thru as "button has been pushed" on sending side.
....
in loop()
{
...
if(buttonPushed)) // button press detected
{
state != state; // toggle state
if(state) // state = true 1
{ // code block
digitalWrite(13,LOW) // send LOW to LED 13 as indicator of state 1
... // process anything else
}
else
{ // state = 0
digitalWrite(13,HIGH) // send HIGH to LED 13 as indicator of state 1
... // process anything else
phamb587:
I really dont get what you mean . Can you explain me clearly
The loop() function is performed continuously. Anything you do there is repeated thousands of times a second. Do you want to send thousands of key press events per second? I didn't think so. So you send the first "becomes" one. Not the rest, where you already know the state.
Vaclav:
// global variables
boolean state = FALSE;
byte buttonPushed; this is generic variable - there is really no button , but whatever your BT code passed thru as "button has been pushed" on sending side.
....
in loop()
{
...
if(buttonPushed)) // button press detected
{
state != state; // toggle state
if(state) // state = true 1
{ // code block
digitalWrite(13,LOW) // send LOW to LED 13 as indicator of state 1
... // process anything else
}
else
{ // state = 0
digitalWrite(13,HIGH) // send HIGH to LED 13 as indicator of state 1
... // process anything else
}
}
.. rest of the loop code
thank for your code . I try and confirm you later if it works
Vaclav:
Nope, Vaclav just do not believe in mindless "cut and paste " of code in quotation brackets.
Perhaps, but when beginners come here for advice, posting as "code" something that doesn't work isn't all that helpful.
That's like saying put lots of salt into your chocolate cake in a cooking forum (when you really mean sugar) but you don't want cooks to mindlessly "cut and paste" your advice.