The last studio introduced integrations using WebHooks as well as new hardware (the OLED display and Piezo) and the mini-studio introduced IFTTT as a tool for combining different services.
The objectives of today's Studio are:
As usual, today's studio will require groups of 3-4.
At least one person will need to write code and interact with the Argon, but everyone should discuss the work and fully participate.
As in the previous studios, all group members will need to be in a GitHub group (and repository)
The link for this studio is: https://classroom.github.com/g/udwi-DLj
This studio will work through an example and require that you build comparable examples from them.
Work through the Conference Room Monitor tutorial, but heed the following modifications:
Launch Slack
drop down menu in the upper rightCreate a new workspace
at the bottom of the menu
pinMode
appropriate for a switch)Add an app or integration
step is difficult to find. To get to it:...
menuAdd App
optionsetup()
to work with a button!)
/*****************************************************************************
Particle Maker Kit Tutorial #3: PIR Motion Sensor
This tutorial uses a Photon and the PIR motion sensor from the Particle Maker
Kit to determine whether a conference room is in use (you could also use it
for many other applications) and post the status to Slack.
******************************************************************************/
int ledPin = D7; // choose the pin for the LED
int inputPin = D4; // choose the PIR sensor pin
bool available; // status of conference room
int motionCounter = 0; // variable to count motion events
boolean update = false; // Time to post an update?
Timer timer(20000, determineMotion); // software timer to check every 30s
void setup() {
pinMode(ledPin, OUTPUT); // set LED as output
pinMode(inputPin, INPUT); // set sensor as input
timer.start(); // start the determineMotion timer
Serial.begin(9600);
}
void determineMotion() { // this function determines if there's motion
if(motionCounter < 2) { // if very little motion was detected
update = true;
available = true; // set the status to available
} else if (motionCounter >= 2) {
if(available == true) { // only publish if the status changed
update = true;
available = false; // set the status to in use
}
}
motionCounter = 0; // reset motion counter
}
// Update to webhook (and LED)
void postUpdatesIfNeeded() {
if(update) {
update = false;
digitalWrite(ledPin, available);
if(available) {
Particle.publish("conf_avail", "Available", PRIVATE); //publish to conf_avail webhook
} else {
Particle.publish("conf_inuse", "Inuse", PRIVATE); //publish to conf_inuse webhook
}
}
}
void loop() {
if (digitalRead(inputPin) == HIGH) { // check if the input is HIGH
motionCounter++; // increment motion counter
Serial.println("Motion!");
}
postUpdatesIfNeeded();
delay(500); // wait 0.5s
}
pinMode()
!README.md
Commit your work to GitHub:
Complete any unfinished work and commit it to your repo by 11:59pm Sunday