Crazyclock is a clock that can go faster or slower than normal clock.
In other words: crazy minute can last more than, or less than 60 real seconds. Crazy time can be scaled to run for example twice as fast:
- By default Crazyclock starts in normal mode
- it shows real time
- Let's assume that at 12:00 someone goes crazy
- time should run twice as fast as normal time
- As a result after one minute the Crazyclock will show 12:02
For more details see How it Works section.
You are going to need:
- ESP8266 (wemos or nodemcu version)
- 1602 LCD screen with i2c converter
- rotary encoder, i.e. KY-040
- real time clock, i.e. DS3231
In short Crazyclock uses real time and a scaling factor to calculate crazy time:
- it checks how much of real time passed
- and calculates the crazy time using the scaling factor
It calculates the crazy time in the main program loop without using delay(ms)
function.
- When the program starts it shows normal time
- scaling factor being
1
- scaling factor being
- At some time t0 someone changes the scaling factor to
2
- Now we should show time flying twice as fast. We do it by:
- calculating how much of real time passed
- multiplying tha by
2
- adding that to t0
- Get t0 as the real time when scaling factor was configured
- And c0 as the crazy time for that moment
- Let T be how much time passed since t0:
- T = tnow - t0
- And then it knows how much crazy time passed from t0:
- C = T * scaling factor
- For current crazy time we get crazy starting point c0 and increase it by passed crazy time C:
- cnow = c0 + C
You might want to install C++ Tools plugin.
Install Clang-Format extension
and choose it for formatting (xaver.clang-format
).
To format currently edited file use [ctlr] + [shift] + [i]
keyboard shortcut.
To format all files at once (with clang-format installed on your system):
clang-format -style=llvm -i crazyclock.ino
find src -iname "*.h" -o -iname "*.cpp" -o -iname "*.ino" | xargs clang-format -style=llvm -i
We keep components in src folder.
-
Create configuration file:
arduino-cli config init
-
Add esp8266 URL for board manager:
arduino-cli config add board_manager.additional_urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
-
Configure the autocompletion for command-line (optional step)
-
Install Wemos D1 Mini board:
arduino-cli core update-index arduino-cli core install esp8266:esp8266 arduino-cli core list arduino-cli board listall esp8266:d1
- Watch for logs with:
sudo dmesg -w | grep USB
- Connect your device via USB
- Write down the ID for the USB device (i.e. ttyUSB0)
- Show permissions for the device:
ls -lah /dev/ttyUSB0
- Write down the group of the device (i.e. uucp)
- Add your user to the above group:
sudo usermod -a -G uucp $USER
- logout and login again to apply changes
In root directory:
-
Install required libraries (i.e. hd44780):
arduino-cli lib install "hd44780" "NTPClient" "RotaryEncoder" "Time" "Timezone" "DS3231" "Debouncer"
-
Compile:
arduino-cli --verbose compile --fqbn esp8266:esp8266:d1
-
Upload:
arduino-cli --verbose upload --fqbn esp8266:esp8266:d1 --port /dev/ttyUSB0
- AUnit library:
arduino-cli lib install AUnit
- EpoxyDuino v1.6.0 in crazyclock
libraries/EpoxyDuino
folder - Set environment variable
ARDUINO_CLI_DIR
forarduino-cli
libraries:export ARDUINO_CLI_DIR=${HOME}/Arduino
- Execute tests:
make -C src/ make_all && make -C src/ runtests