3.9-3.10 IoT Light by Neopixel LED Matrix
Learning Objectives:
After this lesson, students can
1. SET UP YOUR ADAFRUIT.IO PLATFORM
0. Sign in to io.adafruit.com
A. FEED
1. In IO > Feeds, create a new group "LTPSS IoT Light".
2. In the group "LTPSS IoT Light", create a new feed "pattern".

In the above example, the feed key will be "ltpss-iot-light.pattern". Please refer to your own screen.
B. DASHBOARD
1. In IO > Feeds, create a new dashboard "LTPSS IoT Light".
2. In the dashboard "LTPSS IoT Light", set up some controls to control the above feed "pattern" by selecting "Create New Block".

Select the desired block type and the feed "pattern". You can change the title of the blocks to "PATTERN CHOICE".
For example:

Press the gear to modify the internal settings again.
Values (0-3):
0: OFF
1: Default pattern when the LED matrix is turned on
2: Pattern 2
3: Pattern 3
2. ARDUINOBLOCKS PROGRAM AND CLASSWORK
1. Sign in to ArduinoBlocks.com
2. Use the project code for CW3.9.1 (for S3 Group 2):
esPNk1m5
3. Create the following functions. Test them when necessary.
- WIFI SSID: DT
- WIFI Password: 11223344
- Adafruit User: See your Adafruit - My Key
- Adafruit Password: See your Adafruit - My Key
- Feed: ....

Turn off the Neopixel LED matrix.
Turn on the Neopixel LED matrix into ONE color described by the RGB values.
4. Create the setup block.

- When the power is on, turn off on-board LED. (It will be turned on later when the MQTT has been connected.)
- The Neopixel LED matrix signal wire (DIN) (green) is connected to Pin D5 of the Wemos D1 board.
- Turn off the Neopixel LED matrix.
- Set a start flag to true. It will be used to publish a default pattern to Adafruit IO platform one time when board is powered on.
- Connect to Adafruit IO plaftorm.
- Subscribe a Topic by the Feed Key in Adafruit IO platform.
(Please change the above "User" and "Feed Key" to the ones in your Adafruit IO settings.)
5. Create the loop block.

- If MQTT is connected, the on-board LED will be ON. Otherwise, the on-board LED will be OFF and the Adafruit connection will be initialised again.
- If it is the first time running in the Loop block, publish "1" (default value) to the Feed in Adafruit IO, so that the display in Adafruit Dashboard and the Wemos D1 board will match to each other. After testing, I found that publishing can only be done in the Loop block.
- Since the subscription call is done in the Setup block, the subscription will be monitored at the background from time to time. Before making a LED pattern choice, we need to store a pattern instance and then use this fixed stored value for decision.
- Please finish other patterns by making other functions, and complete the above patterns. You can use the breathing light as one pattern.
Menu: Projects > Import from file > ...
Select a .abp file.3. CHALLENGES (OPTIONAL)
- Can we change the Neopixel LED matrix into a clock?
https://io.adafruit.com/blog/feature/2016/06/01/time-utilities/
- Can we use a potentiometer to add a local control ?
- Can we add more Adafruit controls to add more features, e.g. a timer, dimmer, colour selector, ...
- Connect to IFTTT to:
- light up NeoPixels when you're near a location
- Turn on lights right before sunset.
- Can we change the Neopixel LED matrix into a clock?