Entropy dictates that all ordered structures will eventually collapse. This includes the collapse of life. Hope, then, hangs on the cycles of creation and destruction, allowing for the resiliency of life.
Water, earth, light and heat, the pillars on which life rests, pulse with specific rhythms, creating cycles that begin and end. These cycles and rhythms are what we use to measure the passage of time.
The Object of DesignWater, or rather ice water, pulses every second, depositing a water particle on top with every pulse. Every ten seconds, a new layer is started, causing all the previous layers to warm up, darkening as a result. Every 60 seconds, the whole ice water structure collapses under its own weight, creating a new cycle.
Earth, or rather lava, as the source of primal earth, pulses every second when the water pulse hits the ground. Every minute, a lava particle is deposited on top. Every 10 minutes, a new layer of lava is started, causing all the previous layers to cool down, darkening in the process. Every 60 minutes, the whole cooled lava structure collapses under its own weight, starting again.
Life, in the form of green structures, pulses every second when the pulses of water and earth hit the ground. Every hour, a new life unit is deposited on top. Every 3 hours, a new layer of life units begins, causing all previous layers to grow older, darkening as a result. Every 12 hours, all layers of life collapse, allowing for a new cycle to begin.
Finally, the sun (light & heat) completes a full cycle every 24 hours, starting at the top as a bright (orange) AM period and crawling to the bottom as a dim (purple) PM period.
The images of these cycles provide the detailed time of day
I’m using the Adafruit MatrixPortal M4 which has a Cortex M4 processor, with an ESP32 co-processor, a LIS3DH accelerometer and several pins and connectors for expansions. For a LED Matrix, I chose the 32x32 RGB LED Matrix Panel with 4mm Pitch. Out of Adafruit’s comprehensive learning guide for their MatrixPortal, the three key steps are on preparing the MatrixPortal,using it with the Arduino IDE and installing the required libraries. More details on how the LED matrix works.
Other pieces of hardware will be added for more services (see “Coming Episodes”, below)
Prose in C++I used to edit using Visual Studio Code (free, open source and full of features) and compile, upload & serial monitor using (the now legacy) Arduino IDE 1.8 (by selecting an external editor under preferences, which keeps the files in sync). But, with the release of Arduino IDE 2.0, this changed. Now I have better autocompletion, pop-up help on functions & variables, simultaneous use of serial monitor and plotter, and many others. Plus, it looks awesome in dark mode.
When starting a new project, I find it a good practice to keep all the code in a single file: this makes it easier for the IDE to find variable & function definitions (and this helps me). As I reach the first functioning draft (because writing code as a hobby is an iterative process I enjoy), I then move certain groups to specific files to keep it all nice & tidy. Plus, this also allows me to access different points in the project with a single click (by selecting the relevant tab) instead of scrolling up & down incessantly.
I don’t have to follow an orthodox C++ file naming scheme because the Arduino IDE performs a few transformations during the sketch build process that allow for greater flexibility. Just know that all.ino files in the sketch folder are concatenated together starting with the matching folder name and then in alphabetical order. To avoid using names in alphabetical order, I use.h extensions and #include them in the main (and only).ino file.
You’ll notice also that I use comments liberally. When I revisit a project, days or weeks later, this lets me recall, understand, and follow who does what and why.
The full code, as it stands today, is contained in five files:
1. declarations.h – libraries, object instantiation, global variables, and global constants. I also add the links to relevant tutorials and/or github repositories associated with these declarations.
2. clockDisplay.h – routines to update the LED matrix display with the Pixeldust simulations and with the current time
3. inputSerial.h – input data from Serial Monitor to update time (hour, minute, second) and other parameters. These routines I reuse in almost every project to avoid recompiling and reloading with every parameter test, not only saving me time, but also saving Flash cycles out of its lifetime (10k cycles for PROGMEM i.e. Flash, 100k for EEPROM) Managing Arduino Memory: Flash, SRAM, EEPROM
4. setup.h – the standard setup() and its associated routines to start resources and initiate the LED Matrix display.
5. designTwo_v3.ino – the main program loop, calling display updates as time elapses
Coming Episodes (Maybe)UsingOther Data Input Methods
- Buttons & Taps. First draft uses any button pressed to go into Config Mode. A Single Tap (i.e., from the accelerometer library) to move to next Config Item. Up/Down Buttons to scroll thru values/options for selected Config Item. Double Tap to exit Config Mode and return to Clock Mode. Still working out best way to display Config Items and their values and maintain Design Principle: no digits nor letters.
- Blynk & Wi-Fi.Blynk provides a simple, but powerful graphical user interface, for both Web & Mobile. I'll reuse routines from my Smart Night Light & Alarm Clock. Once Wi-Fi is enabled, we can get the Time of Day either from Blynk or from an NPT server.
- BLE & MIT App Inventor. Technically a possibility, but I've yet to find out if and how Adafruit exposes BLE from the ESP32 to the M4.
UsingAdditional Hardware (in no particular order)
- Light sensor, to dim the LED Matrix according to ambient light.
- Audio, for simple sound effects, using the JST connector (port A0) to a Class D audio amplifier w/8ohm speaker. Or maybe just a Piezo Buzzer using Robson Couto's Arduino Songs.
- GPS, to acquire local time of day and to dim/brighten the LED matrix based on sunset/sunrise time of location.
- Thermal Camera, only when detecting a living (warm) creature, the LED matrix is turned on.
- EEPROM, to save current time and operational parameters after power is restored. Constant saves on existing Flash memory are a bad practice considering its write life cycle. See Adafruit Forum entry on Flash memory usage or Crisitan Maglie's FlashStorage that includes the disclaimer: IMPROPER USE OF THIS LIBRARY CAN QUICKLY AND PERMANENTLY DESTROY THE FLASH MEMORY OF YOUR MICRO.
- Battery. The challenge will be battery duration (consider a 5V LED matrix always on). May have to experiment with some solar panel setup to assess (aesthetical) feasibility.
- 3D print case & LEDdiffuser. As last add-on to design a holder for the additional hardware.
Comments