- Starting point
- Simple Ambient Orb
- Advanced (Optional): a full fledged ambient Orb
- Going Further
This practice exercise will challenge you to create an ambient calendar alert using a neopixel strip. By the end of the project, you’ll have connected your Particle device to your Google Calendar through IFTTT. This will send an alert to your device a few minutes before an appointment. You’ll have programmed the neopixels to respond by fading up slowly and signalling there’s an event and changing color as the event approaches. Ultimately it will then fade out after the event has begun. To prepare this simple ambient notification system, you’ll get familiar with using
millis() to sequence durational transitions and you’ll get familiar with
for loops, using libraries and programming effects and behaviors using light.
To begin this exercise exercise, start by
Create a circuit containing the neopixel lights.
Create code for your Particle that does the following:
- Includes the necessary libraries e.g. the neopixel library
- Contains a seroes of variables for the pins you’re using.
setupto configure the pins in use and initialize libraries
- Program the leds to turn on (i.e. check that your wiring and code for Neopixels works as expected)
Doing this will allow you to test the components and make sure they are working correctly before going further.
By the end of this (in
- You will have a basic program that will let you quickly test that everythings behaving as you’d expect when you plug in the device!
- You will have practiced controlling all of the LEDs either by progressively turn on all of the LEDs, one by one, or by blinking them
- You can use this to indicate startup for your device is complete, and it is then waiting for event to trigger an ambient notification
We’ll create a simple version of the ambient orb first. It will work as follows:
- You’ll set up IFTTT and connect it to your Google Calendar.
- You’ll create a Particle function in your code.
- You’ll connect the two so that 15 minutes before a meeting on your calendar, IFTTT will call your Particle function.
- Over the 15 minutes between the Particle function being called, and the start of the meeting, program your Neopixel to slowly fade to red.
- For 15 minutes after your meeting was due to start have it slowly fade back to white (the inverse of step 5)
It is recommended that you break this exercise down into several steps, rather than trying to program it all at once. Get one piece of it working bit by bit. For example,
- Program your Neopixel Ring to display a cool white by default.
- Add a Particle Cloud function and use it to change the color to red immediately. Test this with the Particle Console. Great you’ve got one step up and running.
- Program your Neopixel to fade to red over 1 minute using
millis(). Starting with a much faster transition will help you quickly test, iterate and debug it.
- After the initial transition, now program your Neopixel to fade from red back to white over 1 minute using
- With those working as quick transitions, test them working over 15 minutes!
- Finally and once you’re happy with the behavior, hook it up to IFTTT.
While it might seem sensible to hook your code up to IFTTT early, you're better off testing with the Particle console as much as possible and leaving IFTTT to the final steps
Rework the behavior to behave as follows, we want our Ambient Orb to behave as follows:
- 15 minutes before the calendar event starts, the ambient alert will begin displaying.
- It will will fade up slowly for 10 minutes to solid white
- 5 minutes before the meeting, the color will begin to slowly change from white to red over those 5 minutes.
- At the time when the meeting takes place, the ambient display will present as red
- Then it will slowly fade out over 5 more minutes.
In total this is a 20 minute durational event.
This will require you to :
- Configure a Particle cloud function to trigger the sequence
- Connect your device to your Google Calendar using IFTTT and the cloud function you’ve created.
- Navigate the use of
millis()to control durational interactions.
Don't attempt to write the code for this all at once. Break this problem apart into discrete units.
To remotely control the ambient notification
- Add two Particle cloud function(s). One to start the ambient notification and one to stop the notification
- This should update a variable that indicates if the device should display the ambient notification.
- Check if the ambient notification should display.
- If it’s displaying, the notification should unfold over 20 minutes as follows:
- First 5 minutes: It should begin by slowly fading up and displaying a single color (blue or green)
- Middle 10 minutes: It should slowly transition to red over the course of the next 10 minutes.
- 5 minutes after the event: It should slowly fade out to off.
You should also add cloud variables that allow you to see if the timer is running, and the amount of time elapsed in the sequence. This will make it easier to debug and understand what’s happening when your program runs.
Hint: Define the times for each phase of the interaction as global variables. When you’re testing, reduce/divide these times by 10 to make it much quicker to see how your device is behaving. When it’s close to implemented you can then change the times to longer durations. For example
//int COMPLETE_AFTER = 20 * 60 * 1000; // 20 minutes from start to fade out int COMPLETE_AFTER = 2 * 60 * 1000; // FOR TESTING: 2 minutes from start to finish
When programming a device that has a networked interaction, always leave this component to last. You can test the behavior by calling the
Particle.function from the online console.
Only when you’re sure the device is behaving how you want should you connect it and test it with live data. So, the final step should be to use IFTTT and connect it to your calendar.
To connect your calendar to your Particle using IFTTT:
- Create a new applet on IFTTT
- Choose the Google Calendar Service as your trigger. Select the
Any Event Startsoption. Select the calendar you want to use and choose 15 minutes as the Time before an event starts.
- Choose the Particle service as the action. Select the option to
Call a functionand choose the function you’ve defined on your Particle device.
Once you’ve achieved the outcome, you can try some of the below and experiment to improve your coding skills
Particle.function to customize the time / duration of the countdown
Wire up a pushbutton and allow the pushbutton to dismiss the alert if pressed for 3 seconds.