Skip to content

Commit 88ed5d5

Browse files
author
Federico Fissore
committed
Spacebrew update
1 parent 2f7e712 commit 88ed5d5

File tree

8 files changed

+720
-724
lines changed

8 files changed

+720
-724
lines changed

libraries/Bridge/examples/SpacebrewYun/inputOutput/inputOutput.ino

+74-74
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
Input Output
33
44
Demonstrates how to create a sketch that sends and receives all standard
5-
spacebrew data types, and a custom data type. Every time data is
5+
spacebrew data types, and a custom data type. Every time data is
66
received it is output to the Serial monitor.
77
8-
Make sure that your Yun is connected to the internet for this example
8+
Make sure that your Yun is connected to the internet for this example
99
to function properly.
10-
10+
1111
The circuit:
1212
- No circuit required
13-
13+
1414
created 2013
1515
by Julio Terra
16-
16+
1717
This example code is in the public domain.
18-
19-
More information about Spacebrew is available at:
18+
19+
More information about Spacebrew is available at:
2020
http://spacebrew.cc/
21-
21+
2222
*/
2323

2424
#include <Bridge.h>
@@ -33,100 +33,100 @@ int interval = 2000;
3333

3434
int counter = 0;
3535

36-
void setup() {
37-
38-
// start the serial port
39-
Serial.begin(57600);
36+
void setup() {
4037

41-
// for debugging, wait until a serial console is connected
42-
delay(4000);
43-
while (!Serial) {
44-
;
45-
}
38+
// start the serial port
39+
Serial.begin(57600);
4640

47-
// start-up the bridge
48-
Bridge.begin();
41+
// for debugging, wait until a serial console is connected
42+
delay(4000);
43+
while (!Serial) { ; }
4944

50-
// configure the spacebrew object to print status messages to serial
51-
sb.verbose(true);
45+
// start-up the bridge
46+
Bridge.begin();
5247

53-
// configure the spacebrew publisher and subscriber
54-
sb.addPublish("string test", "string");
55-
sb.addPublish("range test", "range");
56-
sb.addPublish("boolean test", "boolean");
57-
sb.addPublish("custom test", "crazy");
58-
sb.addSubscribe("string test", "string");
59-
sb.addSubscribe("range test", "range");
60-
sb.addSubscribe("boolean test", "boolean");
61-
sb.addSubscribe("custom test", "crazy");
48+
// configure the spacebrew object to print status messages to serial
49+
sb.verbose(true);
6250

63-
// register the string message handler method
64-
sb.onRangeMessage(handleRange);
65-
sb.onStringMessage(handleString);
66-
sb.onBooleanMessage(handleBoolean);
67-
sb.onCustomMessage(handleCustom);
51+
// configure the spacebrew publisher and subscriber
52+
sb.addPublish("string test", "string");
53+
sb.addPublish("range test", "range");
54+
sb.addPublish("boolean test", "boolean");
55+
sb.addPublish("custom test", "crazy");
56+
sb.addSubscribe("string test", "string");
57+
sb.addSubscribe("range test", "range");
58+
sb.addSubscribe("boolean test", "boolean");
59+
sb.addSubscribe("custom test", "crazy");
6860

69-
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
70-
sb.connect("sandbox.spacebrew.cc");
61+
// register the string message handler method
62+
sb.onRangeMessage(handleRange);
63+
sb.onStringMessage(handleString);
64+
sb.onBooleanMessage(handleBoolean);
65+
sb.onCustomMessage(handleCustom);
7166

72-
}
67+
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
68+
sb.connect("sandbox.spacebrew.cc");
69+
// we give some time to arduino to connect to sandbox, otherwise the first sb.monitor(); call will give an error
70+
delay(1000);
71+
}
7372

7473

75-
void loop() {
76-
// monitor spacebrew connection for new data
77-
sb.monitor();
74+
void loop() {
75+
// monitor spacebrew connection for new data
76+
sb.monitor();
7877

79-
// connected to spacebrew then send a string every 2 seconds
80-
if ( sb.connected() ) {
78+
// connected to spacebrew then send a string every 2 seconds
79+
if ( sb.connected() ) {
8180

82-
// check if it is time to send a new message
83-
if ( (millis() - last) > interval ) {
84-
String test_str_msg = "testing, testing, ";
85-
test_str_msg += counter;
86-
counter ++;
81+
// check if it is time to send a new message
82+
if ( (millis() - last) > interval ) {
83+
String test_str_msg = "testing, testing, ";
84+
test_str_msg += counter;
85+
counter ++;
8786

88-
sb.send("string test", test_str_msg);
89-
sb.send("range test", 500);
90-
sb.send("boolean test", true);
91-
sb.send("custom test", "youre loco");
87+
sb.send("string test", test_str_msg);
88+
sb.send("range test", 500);
89+
sb.send("boolean test", true);
90+
sb.send("custom test", "youre loco");
9291

93-
last = millis();
92+
last = millis();
9493

95-
}
96-
}
97-
}
94+
}
95+
}
96+
delay(1000);
97+
}
9898

9999
// define handler methods, all standard data type handlers take two appropriate arguments
100100

101101
void handleRange (String route, int value) {
102-
Serial.print("Range msg ");
103-
Serial.print(route);
104-
Serial.print(", value ");
105-
Serial.println(value);
102+
Serial.print("Range msg ");
103+
Serial.print(route);
104+
Serial.print(", value ");
105+
Serial.println(value);
106106
}
107107

108108
void handleString (String route, String value) {
109-
Serial.print("String msg ");
110-
Serial.print(route);
111-
Serial.print(", value ");
112-
Serial.println(value);
109+
Serial.print("String msg ");
110+
Serial.print(route);
111+
Serial.print(", value ");
112+
Serial.println(value);
113113
}
114114

115115
void handleBoolean (String route, boolean value) {
116-
Serial.print("Boolen msg ");
117-
Serial.print(route);
118-
Serial.print(", value ");
119-
Serial.println(value ? "true" : "false");
116+
Serial.print("Boolen msg ");
117+
Serial.print(route);
118+
Serial.print(", value ");
119+
Serial.println(value ? "true" : "false");
120120
}
121121

122122
// custom data type handlers takes three String arguments
123123

124124
void handleCustom (String route, String value, String type) {
125-
Serial.print("Custom msg ");
126-
Serial.print(route);
127-
Serial.print(" of type ");
128-
Serial.print(type);
129-
Serial.print(", value ");
130-
Serial.println(value);
125+
Serial.print("Custom msg ");
126+
Serial.print(route);
127+
Serial.print(" of type ");
128+
Serial.print(type);
129+
Serial.print(", value ");
130+
Serial.println(value);
131131
}
132132

Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
/*
22
Spacebrew Boolean
3-
3+
44
Demonstrates how to create a sketch that sends and receives a
5-
boolean value to and from Spacebrew. Every time the buttton is
6-
pressed (or other digital input component) a spacebrew message
7-
is sent. The sketch also accepts analog range messages from
5+
boolean value to and from Spacebrew. Every time the buttton is
6+
pressed (or other digital input component) a spacebrew message
7+
is sent. The sketch also accepts analog range messages from
88
other Spacebrew apps.
99
10-
Make sure that your Yun is connected to the internet for this example
10+
Make sure that your Yun is connected to the internet for this example
1111
to function properly.
12-
12+
1313
The circuit:
1414
- Button connected to Yun, using the Arduino's internal pullup resistor.
15-
15+
1616
created 2013
1717
by Julio Terra
18-
18+
1919
This example code is in the public domain.
20-
21-
More information about Spacebrew is available at:
20+
21+
More information about Spacebrew is available at:
2222
http://spacebrew.cc/
23-
23+
2424
*/
2525

2626
#include <Bridge.h>
@@ -33,59 +33,57 @@ SpacebrewYun sb = SpacebrewYun("spacebrewYun Boolean", "Boolean sender and recei
3333
int last_value = 0;
3434

3535
// create variables to manage interval between each time we send a string
36-
void setup() {
36+
void setup() {
3737

38-
// start the serial port
39-
Serial.begin(57600);
38+
// start the serial port
39+
Serial.begin(57600);
4040

41-
// for debugging, wait until a serial console is connected
42-
delay(4000);
43-
while (!Serial) {
44-
;
45-
}
41+
// for debugging, wait until a serial console is connected
42+
delay(4000);
43+
while (!Serial) { ; }
4644

47-
// start-up the bridge
48-
Bridge.begin();
45+
// start-up the bridge
46+
Bridge.begin();
4947

50-
// configure the spacebrew object to print status messages to serial
51-
sb.verbose(true);
48+
// configure the spacebrew object to print status messages to serial
49+
sb.verbose(true);
5250

53-
// configure the spacebrew publisher and subscriber
54-
sb.addPublish("physical button", "boolean");
55-
sb.addSubscribe("virtual button", "boolean");
51+
// configure the spacebrew publisher and subscriber
52+
sb.addPublish("physical button", "boolean");
53+
sb.addSubscribe("virtual button", "boolean");
5654

57-
// register the string message handler method
58-
sb.onBooleanMessage(handleBoolean);
55+
// register the string message handler method
56+
sb.onBooleanMessage(handleBoolean);
5957

60-
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
61-
sb.connect("sandbox.spacebrew.cc");
58+
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
59+
sb.connect("sandbox.spacebrew.cc");
6260

63-
pinMode(3, INPUT);
64-
digitalWrite(3, HIGH);
65-
}
61+
pinMode(3, INPUT);
62+
digitalWrite(3, HIGH);
63+
}
6664

6765

68-
void loop() {
69-
// monitor spacebrew connection for new data
70-
sb.monitor();
66+
void loop() {
67+
// monitor spacebrew connection for new data
68+
sb.monitor();
7169

72-
// connected to spacebrew then send a new value whenever the pot value changes
73-
if ( sb.connected() ) {
74-
int cur_value = digitalRead(3);
75-
if ( last_value != cur_value ) {
76-
if (cur_value == HIGH) sb.send("physical button", false);
77-
else sb.send("physical button", true);
78-
last_value = cur_value;
79-
}
80-
}
81-
}
70+
// connected to spacebrew then send a new value whenever the pot value changes
71+
if ( sb.connected() ) {
72+
int cur_value = digitalRead(3);
73+
if ( last_value != cur_value ) {
74+
if (cur_value == HIGH) sb.send("physical button", false);
75+
else sb.send("physical button", true);
76+
last_value = cur_value;
77+
}
78+
}
79+
}
8280

83-
// handler method that is called whenever a new string message is received
81+
// handler method that is called whenever a new string message is received
8482
void handleBoolean (String route, boolean value) {
85-
// print the message that was received
86-
Serial.print("From ");
87-
Serial.print(route);
88-
Serial.print(", received msg: ");
89-
Serial.println(value ? "true" : "false");
83+
// print the message that was received
84+
Serial.print("From ");
85+
Serial.print(route);
86+
Serial.print(", received msg: ");
87+
Serial.println(value ? "true" : "false");
9088
}
9189

0 commit comments

Comments
 (0)