Skip to content

Instantly share code, notes, and snippets.

@boxalljohn
Created April 6, 2022 08:06
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 boxalljohn/ab7c5bfb77da1ca3f0f2c0c036fd524a to your computer and use it in GitHub Desktop.
Save boxalljohn/ab7c5bfb77da1ca3f0f2c0c036fd524a to your computer and use it in GitHub Desktop.
WFH messaging system code for Particle Photon
// WFH Messaging system.
// Modified version of code provided by particle.io documentation.
// Use at your own risk.
int led0 = D0;
int led1 = D1;
int led2 = D2;
int led3 = D3;
int led4 = D4;
int buzzer = D5;
void setup()
{
// set pins connected to LEDs and buzzer as outputs
pinMode(led0, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(buzzer, OUTPUT);
// We are also going to declare a Particle.function so that we can turn the LEDs on and off from the cloud.
Particle.function("led",ledToggle);
// This is saying that when we ask the cloud for the function "led", it will employ the function ledToggle() from this app.
// Turn off LEDs upon reset
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(buzzer, LOW);
}
void loop()
{
// Nothing to do here as waiting for text from control webpage
}
void soundAlert()
{
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
}
void coffeeAlert()
{
for (int i=0; i<5; i++)
{
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
delay(100);
}
}
void waterAlert()
{
for (int i=0; i<2; i++)
{
digitalWrite(buzzer, HIGH);
delay(500);
digitalWrite(buzzer, LOW);
delay(100);
}
}
int ledToggle(String command) {
// function receives a string from control webpage (the commands such as D0On) and acts on them
if (command=="D0On") {
digitalWrite(led0,HIGH); // in a meeting - DND
digitalWrite(led1,LOW); // turn off working alone LED
digitalWrite(led4,LOW); // turn off finished for the day LED
soundAlert();
return 1;
}
else if (command=="D1On") {
digitalWrite(led1,HIGH); // working alone
digitalWrite(led0,LOW); // turn off DND LED
digitalWrite(led4,LOW); // turn off finished for the day LED
soundAlert();
return 0;
}
else if (command=="D2On") {
digitalWrite(led2,HIGH); // coffee request
coffeeAlert();
delay(2000);
digitalWrite(led2,LOW);
return 0;
}
else if (command=="D3On") {
digitalWrite(led3,HIGH); // water request
waterAlert();
delay(2000);
digitalWrite(led3,LOW);
return 0;
}
else if (command=="D4On") {
digitalWrite(led4,HIGH); // finished for the day
digitalWrite(led0,LOW); // cancel DND LED if on
digitalWrite(led1,LOW); // cancel working alone LED if on
soundAlert();
return 0;
}
else {
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment