time zone. Here’s what your code should look
like (Figure
D
) but with your details inside the
quote marks. To find your correct time zone, go
to worldtimeapi.org/timezones. If your location
is not listed, look for a city in the same time
zone. Call your file secrets.py and save it to your
CIRCUITPY drive.
7. TEST YOUR INTERNET CONNECTION
This bit of code, iotest.py, is designed to test
that your internet and Adafruit IO account are
working correctly (Figure
E
). In lines 11 to 13,
the function log_data connects to the network
and pushes data from the onboard temperature
sensor to the temperature feed. I don’t want my
FunHouse to push data to Adafruit IO too often, so
on line 9 I checked for the current local time and
date, then stored that information in a variable
called timestamp. Line 18 checks again for the
current local time and date and then subtracts
the information contained in timestamp. If the
difference between the two is greater than 30
seconds, it will set timestamp to the current local
time and date then call the log_data function to
send your data to Adafruit IO.
Open up your code editor again and create a
new file containing this test code. You can type it
out or copy and paste it; you can find all the test
code at github.com/helenleigh/funhouse. Save
this file onto your CIRCUITPY drive as code.py and
it will start running.
WARNING: If you already have a code.py file on
your CIRCUITPY drive you will save over it, so make
sure you back up any code before saving over it.
After 30 seconds check your temperature feed
and you should see your first data point! For your
own code, you probably don’t need to check the
temperature every 30 seconds.
You should also spend some time exploring
what Adafruit IO can do for your connected
projects. To start, try creating feeds for the other
sensors on your FunHouse then setting up a
dashboard to visualize your data and interact
with your board.
8. ACTIVATE YOUR SENSOR AND OUTPUTS
This code, inputsoutputstest.py, tries out the
PIR sensor, the servomotor, and the NeoPixel
strip (Figure
F
). Lines 1 through 7 pull in the
libraries you need and lines 9 through 14 set up
your outputs. If you’ve attached your servo to pin
A1 instead of A0, or if you want to turn up the
brightness of your NeoPixels, this is where
you’d do it.
The next chunk of code creates a function
called color_chase that makes the strip of
NeoPixels fill with color, one after another. After
that, we define the RGB value of each color. In
the while True loop, if the PIR sensor detects
motion it will move the servo, light up the
95
make.co
D
E
E
M78_092-97_HalloweenHelen_F1.indd 95M78_092-97_HalloweenHelen_F1.indd 95 7/13/21 12:37 PM7/13/21 12:37 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.84.32