Hardware Reference
In-Depth Information
4.6 Bridge
We explore again Bridge using Python. In this scenario, we try to turn on/off a LED from
Python. We use LED pin 13 for testing. The scenario can be described as follows:
• Python app send 0 or 1 via Bridge client
• Arduino app will receive this message
• If Arduino receives value 1, Arduino will turn on LED 13
• Otherwise, if value 0 is received, Arduino will turn off LED 13
Firstly, we createa Arduino app using Arduino Sketch. Write this code.
#include <Bridge.h>
int
led =
13
;
char
val[
1
];
void
setup
()
{
Serial.begin(
9600
);
Bridge.begin();
}
void
loop
()
{
Bridge.get("led",val,
1
);
if
(String(val)!="") {
Serial.print("val=");
Serial.println(val[
0
]);
int
n = val[
0
]-
'0'
;
if
(n==
1
)
digitalWrite(led,HIGH);
else
digitalWrite(led,LOW);
delay(
1000
);
