Skip to content

Instantly share code, notes, and snippets.

@cromwellryan
Created June 26, 2020 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cromwellryan/80547b28f747a1d8232bef0fd5566415 to your computer and use it in GitHub Desktop.
Save cromwellryan/80547b28f747a1d8232bef0fd5566415 to your computer and use it in GitHub Desktop.
// set up the 'dadStatus' feed
AdafruitIO_Feed *dadStatus = io.feed("dad-status");
/* LED Friendly names */
const int inMeetingLed = 15;
const int headphonesOnLed = 14;
void clear() {
digitalWrite(inMeetingLed, LOW);
digitalWrite(headphonesOnLed, LOW);
}
/* These are made available as Particle Cloud Functions
* so I can call them from anywhere */
int goInAMeeting() {
digitalWrite(inMeetingLed, HIGH);
digitalWrite(headphonesOnLed, HIGH);
}
int goHeadphonesOnly() {
digitalWrite(inMeetingLed, LOW);
digitalWrite(headphonesOnLed, HIGH);
}
int goAvailable() {
clear();
}
void setup() {
// start the serial connection
Serial.begin(115200);
// wait for serial monitor to open
while(! Serial);
Serial.print("Connecting to Adafruit IO");
// connect to io.adafruit.com
io.connect();
// set up a message handler for the count feed.
// the handleMessage function (defined below)
// will be called whenever a message is
// received from adafruit io.
dadStatus->onMessage(handleMessage);
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
dadStatus->get();
pinMode(inMeetingLed, OUTPUT);
pinMode(headphonesOnLed, OUTPUT);
clear();
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
}
// this function is called whenever a 'dadStatus' message
// is received from Adafruit IO. it was attached to
// the dadStatus feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {
Serial.print("received <- ");
Serial.println(data->value());
if (!strcmp(data->value(), "MEETING")) {
Serial.printf("\nIt meeting!");
goInAMeeting();
}
if (!strcmp(data->value(), "THINKING")) {
Serial.printf("\nThinking!");
goHeadphonesOnly();
}
if (!strcmp(data->value(), "AVAILABLE")) {
Serial.printf("\nAvailable!");
goAvailable();
}
}
/* LED Friendly names */
int inMeetingLed = D0;
int headphonesOnLed = D3;
void clear() {
digitalWrite(inMeetingLed, LOW);
digitalWrite(headphonesOnLed, LOW);
}
/* These are made available as Particle Cloud Functions
* so I can call them from anywhere */
int goInAMeeting(String _extra) {
digitalWrite(inMeetingLed, HIGH);
digitalWrite(headphonesOnLed, HIGH);
}
int goHeadphonesOnly(String _extra) {
digitalWrite(inMeetingLed, LOW);
digitalWrite(headphonesOnLed, HIGH);
}
int goAvailable(String _extra) {
clear();
}
void setup() {
pinMode(inMeetingLed, OUTPUT);
pinMode(headphonesOnLed, OUTPUT);
clear();
bool success = false;
success = Particle.function("goInAMeeting", goInAMeeting);
success = Particle.function("goHeadphonesOnly", goHeadphonesOnly);
success = Particle.function("goAvailable", goAvailable);
/* Probably shouldn't be so presumptuous
* with the whole "success thing", but YOLO */
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment