Skip to content

Commit ac13346

Browse files
committed
use 'digital' for feed name in both digital examples
1 parent cfd31d1 commit ac13346

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

examples/adafruitio_06_digital_in/adafruitio_06_digital_in.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
bool current = false;
2727
bool last = false;
2828

29-
// set up the 'button' feed
30-
AdafruitIO_Feed *button = io.feed("button");
29+
// set up the 'digital' feed
30+
AdafruitIO_Feed *digital = io.feed("digital");
3131

3232
void setup() {
3333

@@ -76,10 +76,10 @@ void loop() {
7676
if(current == last)
7777
return;
7878

79-
// save the current state to the button feed
79+
// save the current state to the 'digital' feed on adafruit io
8080
Serial.print("sending button -> ");
8181
Serial.println(current);
82-
button->save(current);
82+
digital->save(current);
8383

8484
// store last button state
8585
last = current;

examples/adafruitio_07_digital_out/adafruitio_07_digital_out.ino

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
// digital pin 5
2323
#define LED_PIN 5
2424

25-
// set up the 'led' feed
26-
AdafruitIO_Feed *led = io.feed("led");
25+
// set up the 'digital' feed
26+
AdafruitIO_Feed *digital = io.feed("digital");
2727

2828
void setup() {
2929

@@ -40,6 +40,12 @@ void setup() {
4040
Serial.print("Connecting to Adafruit IO");
4141
io.connect();
4242

43+
// set up a message handler for the 'digital' feed.
44+
// the handleMessage function (defined below)
45+
// will be called whenever a message is
46+
// received from adafruit io.
47+
digital->onMessage(handleMessage);
48+
4349
// wait for a connection
4450
while(io.status() < AIO_CONNECTED) {
4551
Serial.print(".");
@@ -60,8 +66,21 @@ void loop() {
6066
// io.adafruit.com, and processes any incoming data.
6167
io.run();
6268

69+
}
70+
71+
// this function is called whenever an 'digital' feed message
72+
// is received from Adafruit IO. it was attached to
73+
// the 'digital' feed in the setup() function above.
74+
void handleMessage(AdafruitIO_Data *data) {
75+
76+
Serial.print("received <- ");
77+
78+
if(data->toPinLevel() == HIGH)
79+
Serial.println("HIGH");
80+
else
81+
Serial.println("LOW");
82+
6383
// write the current state to the led
64-
digitalWrite(LED_PIN, led->data->toPinLevel());
84+
digitalWrite(LED_PIN, data->toPinLevel());
6585

6686
}
67-

0 commit comments

Comments
 (0)