mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-08 11:22:40 +03:00
Run new astyle formatter against all the examples
This commit is contained in:
@@ -2,23 +2,23 @@
|
||||
Input Output
|
||||
|
||||
Demonstrates how to create a sketch that sends and receives all standard
|
||||
spacebrew data types, and a custom data type. Every time data is
|
||||
spacebrew data types, and a custom data type. Every time data is
|
||||
received it is output to the Serial monitor.
|
||||
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
to function properly.
|
||||
|
||||
|
||||
The circuit:
|
||||
- No circuit required
|
||||
|
||||
|
||||
created 2013
|
||||
by Julio Terra
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
http://spacebrew.cc/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
@@ -33,98 +33,100 @@ int interval = 2000;
|
||||
|
||||
int counter = 0;
|
||||
|
||||
void setup() {
|
||||
void setup() {
|
||||
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("string test", "string");
|
||||
sb.addPublish("range test", "range");
|
||||
sb.addPublish("boolean test", "boolean");
|
||||
sb.addPublish("custom test", "crazy");
|
||||
sb.addSubscribe("string test", "string");
|
||||
sb.addSubscribe("range test", "range");
|
||||
sb.addSubscribe("boolean test", "boolean");
|
||||
sb.addSubscribe("custom test", "crazy");
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("string test", "string");
|
||||
sb.addPublish("range test", "range");
|
||||
sb.addPublish("boolean test", "boolean");
|
||||
sb.addPublish("custom test", "crazy");
|
||||
sb.addSubscribe("string test", "string");
|
||||
sb.addSubscribe("range test", "range");
|
||||
sb.addSubscribe("boolean test", "boolean");
|
||||
sb.addSubscribe("custom test", "crazy");
|
||||
|
||||
// register the string message handler method
|
||||
sb.onRangeMessage(handleRange);
|
||||
sb.onStringMessage(handleString);
|
||||
sb.onBooleanMessage(handleBoolean);
|
||||
sb.onCustomMessage(handleCustom);
|
||||
// register the string message handler method
|
||||
sb.onRangeMessage(handleRange);
|
||||
sb.onStringMessage(handleString);
|
||||
sb.onBooleanMessage(handleBoolean);
|
||||
sb.onCustomMessage(handleCustom);
|
||||
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a string every 2 seconds
|
||||
if ( sb.connected() ) {
|
||||
// connected to spacebrew then send a string every 2 seconds
|
||||
if ( sb.connected() ) {
|
||||
|
||||
// check if it is time to send a new message
|
||||
if ( (millis() - last) > interval ) {
|
||||
String test_str_msg = "testing, testing, ";
|
||||
test_str_msg += counter;
|
||||
counter ++;
|
||||
// check if it is time to send a new message
|
||||
if ( (millis() - last) > interval ) {
|
||||
String test_str_msg = "testing, testing, ";
|
||||
test_str_msg += counter;
|
||||
counter ++;
|
||||
|
||||
sb.send("string test", test_str_msg);
|
||||
sb.send("range test", 500);
|
||||
sb.send("boolean test", true);
|
||||
sb.send("custom test", "youre loco");
|
||||
sb.send("string test", test_str_msg);
|
||||
sb.send("range test", 500);
|
||||
sb.send("boolean test", true);
|
||||
sb.send("custom test", "youre loco");
|
||||
|
||||
last = millis();
|
||||
last = millis();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// define handler methods, all standard data type handlers take two appropriate arguments
|
||||
|
||||
void handleRange (String route, int value) {
|
||||
Serial.print("Range msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
Serial.print("Range msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
void handleString (String route, String value) {
|
||||
Serial.print("String msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
Serial.print("String msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
void handleBoolean (String route, boolean value) {
|
||||
Serial.print("Boolen msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value ? "true" : "false");
|
||||
Serial.print("Boolen msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value ? "true" : "false");
|
||||
}
|
||||
|
||||
// custom data type handlers takes three String arguments
|
||||
|
||||
void handleCustom (String route, String value, String type) {
|
||||
Serial.print("Custom msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(" of type ");
|
||||
Serial.print(type);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
Serial.print("Custom msg ");
|
||||
Serial.print(route);
|
||||
Serial.print(" of type ");
|
||||
Serial.print(type);
|
||||
Serial.print(", value ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
|
@@ -1,26 +1,26 @@
|
||||
/*
|
||||
Spacebrew Boolean
|
||||
|
||||
|
||||
Demonstrates how to create a sketch that sends and receives a
|
||||
boolean value to and from Spacebrew. Every time the buttton is
|
||||
pressed (or other digital input component) a spacebrew message
|
||||
is sent. The sketch also accepts analog range messages from
|
||||
boolean value to and from Spacebrew. Every time the buttton is
|
||||
pressed (or other digital input component) a spacebrew message
|
||||
is sent. The sketch also accepts analog range messages from
|
||||
other Spacebrew apps.
|
||||
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
to function properly.
|
||||
|
||||
|
||||
The circuit:
|
||||
- Button connected to Yun, using the Arduino's internal pullup resistor.
|
||||
|
||||
|
||||
created 2013
|
||||
by Julio Terra
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
http://spacebrew.cc/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
@@ -33,57 +33,59 @@ SpacebrewYun sb = SpacebrewYun("spacebrewYun Boolean", "Boolean sender and recei
|
||||
int last_value = 0;
|
||||
|
||||
// create variables to manage interval between each time we send a string
|
||||
void setup() {
|
||||
void setup() {
|
||||
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("physical button", "boolean");
|
||||
sb.addSubscribe("virtual button", "boolean");
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("physical button", "boolean");
|
||||
sb.addSubscribe("virtual button", "boolean");
|
||||
|
||||
// register the string message handler method
|
||||
sb.onBooleanMessage(handleBoolean);
|
||||
// register the string message handler method
|
||||
sb.onBooleanMessage(handleBoolean);
|
||||
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
|
||||
pinMode(3, INPUT);
|
||||
digitalWrite(3, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a new value whenever the pot value changes
|
||||
if ( sb.connected() ) {
|
||||
int cur_value = digitalRead(3);
|
||||
if ( last_value != cur_value ) {
|
||||
if (cur_value == HIGH) sb.send("physical button", false);
|
||||
else sb.send("physical button", true);
|
||||
last_value = cur_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleBoolean (String route, boolean value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value ? "true" : "false");
|
||||
pinMode(3, INPUT);
|
||||
digitalWrite(3, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a new value whenever the pot value changes
|
||||
if ( sb.connected() ) {
|
||||
int cur_value = digitalRead(3);
|
||||
if ( last_value != cur_value ) {
|
||||
if (cur_value == HIGH) sb.send("physical button", false);
|
||||
else sb.send("physical button", true);
|
||||
last_value = cur_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleBoolean (String route, boolean value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value ? "true" : "false");
|
||||
}
|
||||
|
||||
|
@@ -1,27 +1,27 @@
|
||||
/*
|
||||
Spacebrew Range
|
||||
|
||||
|
||||
Demonstrates how to create a sketch that sends and receives analog
|
||||
range value to and from Spacebrew. Every time the state of the
|
||||
range value to and from Spacebrew. Every time the state of the
|
||||
potentiometer (or other analog input component) change a spacebrew
|
||||
message is sent. The sketch also accepts analog range messages from
|
||||
message is sent. The sketch also accepts analog range messages from
|
||||
other Spacebrew apps.
|
||||
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
to function properly.
|
||||
|
||||
|
||||
The circuit:
|
||||
- Potentiometer connected to Yun. Middle pin connected to analog pin A0,
|
||||
- Potentiometer connected to Yun. Middle pin connected to analog pin A0,
|
||||
other pins connected to 5v and GND pins.
|
||||
|
||||
|
||||
created 2013
|
||||
by Julio Terra
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
http://spacebrew.cc/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
@@ -34,53 +34,55 @@ SpacebrewYun sb = SpacebrewYun("spacebrewYun Range", "Range sender and receiver"
|
||||
int last_value = 0;
|
||||
|
||||
// create variables to manage interval between each time we send a string
|
||||
void setup() {
|
||||
void setup() {
|
||||
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("physical pot", "range");
|
||||
sb.addSubscribe("virtual pot", "range");
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("physical pot", "range");
|
||||
sb.addSubscribe("virtual pot", "range");
|
||||
|
||||
// register the string message handler method
|
||||
sb.onRangeMessage(handleRange);
|
||||
// register the string message handler method
|
||||
sb.onRangeMessage(handleRange);
|
||||
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a new value whenever the pot value changes
|
||||
if ( sb.connected() ) {
|
||||
int cur_value = analogRead(A0);
|
||||
if ( last_value != cur_value ) {
|
||||
sb.send("physical pot", cur_value);
|
||||
last_value = cur_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleRange (String route, int value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value);
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a new value whenever the pot value changes
|
||||
if ( sb.connected() ) {
|
||||
int cur_value = analogRead(A0);
|
||||
if ( last_value != cur_value ) {
|
||||
sb.send("physical pot", cur_value);
|
||||
last_value = cur_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleRange (String route, int value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
|
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
Spacebrew String
|
||||
|
||||
|
||||
Demonstrates how to create a sketch that sends and receives strings
|
||||
to and from Spacebrew. Every time string data is received it
|
||||
to and from Spacebrew. Every time string data is received it
|
||||
is output to the Serial monitor.
|
||||
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
Make sure that your Yun is connected to the internet for this example
|
||||
to function properly.
|
||||
|
||||
|
||||
The circuit:
|
||||
- No circuit required
|
||||
|
||||
|
||||
created 2013
|
||||
by Julio Terra
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
|
||||
More information about Spacebrew is available at:
|
||||
http://spacebrew.cc/
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <Bridge.h>
|
||||
@@ -31,54 +31,56 @@ SpacebrewYun sb = SpacebrewYun("spacebrewYun Strings", "String sender and receiv
|
||||
long last_time = 0;
|
||||
int interval = 2000;
|
||||
|
||||
void setup() {
|
||||
void setup() {
|
||||
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
// start the serial port
|
||||
Serial.begin(57600);
|
||||
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) { ; }
|
||||
// for debugging, wait until a serial console is connected
|
||||
delay(4000);
|
||||
while (!Serial) {
|
||||
;
|
||||
}
|
||||
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
// start-up the bridge
|
||||
Bridge.begin();
|
||||
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
// configure the spacebrew object to print status messages to serial
|
||||
sb.verbose(true);
|
||||
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("speak", "string");
|
||||
sb.addSubscribe("listen", "string");
|
||||
// configure the spacebrew publisher and subscriber
|
||||
sb.addPublish("speak", "string");
|
||||
sb.addSubscribe("listen", "string");
|
||||
|
||||
// register the string message handler method
|
||||
sb.onStringMessage(handleString);
|
||||
// register the string message handler method
|
||||
sb.onStringMessage(handleString);
|
||||
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a string every 2 seconds
|
||||
if ( sb.connected() ) {
|
||||
|
||||
// check if it is time to send a new message
|
||||
if ( (millis() - last_time) > interval ) {
|
||||
sb.send("speak", "is anybody out there?");
|
||||
last_time = millis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleString (String route, String value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value);
|
||||
// connect to cloud spacebrew server at "sandbox.spacebrew.cc"
|
||||
sb.connect("sandbox.spacebrew.cc");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// monitor spacebrew connection for new data
|
||||
sb.monitor();
|
||||
|
||||
// connected to spacebrew then send a string every 2 seconds
|
||||
if ( sb.connected() ) {
|
||||
|
||||
// check if it is time to send a new message
|
||||
if ( (millis() - last_time) > interval ) {
|
||||
sb.send("speak", "is anybody out there?");
|
||||
last_time = millis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handler method that is called whenever a new string message is received
|
||||
void handleString (String route, String value) {
|
||||
// print the message that was received
|
||||
Serial.print("From ");
|
||||
Serial.print(route);
|
||||
Serial.print(", received msg: ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user