Skip to content

Clock with flexible second time driven by rotary encoder

Notifications You must be signed in to change notification settings

The-Coobaz/crazyclock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crazyclock

Continuous Integration

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:

  1. By default Crazyclock starts in normal mode
    • it shows real time
  2. Let's assume that at 12:00 someone goes crazy
    • time should run twice as fast as normal time
  3. As a result after one minute the Crazyclock will show 12:02

For more details see How it Works section.

Table of Content

Hardware

You are going to need:

Schema

Fritzing Wemos D1 Mini schema

How it Works

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.

Simple Example

  1. When the program starts it shows normal time
    • scaling factor being 1
  2. At some time t0 someone changes the scaling factor to 2
  3. 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

When the Scaling Factor Changes

  1. Get t0 as the real time when scaling factor was configured
  2. And c0 as the crazy time for that moment
  3. Let T be how much time passed since t0:
    • T = tnow - t0
  4. And then it knows how much crazy time passed from t0:
    • C = T * scaling factor
  5. For current crazy time we get crazy starting point c0 and increase it by passed crazy time C:
    • cnow = c0 + C

Development

VS Code

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.

Console

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

Working with Arduino IDE

We keep components in src folder.

Working with arduino-cli

Arduino CLI setup

  1. Install arduino-cli

  2. Create configuration file: arduino-cli config init

  3. Add esp8266 URL for board manager:

    arduino-cli config add board_manager.additional_urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
    
  4. Configure the autocompletion for command-line (optional step)

  5. 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

Connecting esp-8266 (or Wemos)

  1. Watch for logs with: sudo dmesg -w | grep USB
  2. Connect your device via USB
  3. Write down the ID for the USB device (i.e. ttyUSB0)
  4. Show permissions for the device: ls -lah /dev/ttyUSB0
  5. Write down the group of the device (i.e. uucp)
  6. Add your user to the above group: sudo usermod -a -G uucp $USER
  7. logout and login again to apply changes

Compile and Upload

In root directory:

  1. Install required libraries (i.e. hd44780):

    arduino-cli lib install "hd44780" "NTPClient" "RotaryEncoder" "Time" "Timezone" "DS3231" "Debouncer"
  2. Compile: arduino-cli --verbose compile --fqbn esp8266:esp8266:d1

  3. Upload: arduino-cli --verbose upload --fqbn esp8266:esp8266:d1 --port /dev/ttyUSB0

Fritzing Parts

  1. KY-040 Rotary Encoder
  2. Wemos D1 Mini

Automated tests

Requirements

  1. AUnit library: arduino-cli lib install AUnit
  2. EpoxyDuino v1.6.0 in crazyclock libraries/EpoxyDuino folder
  3. Set environment variable ARDUINO_CLI_DIR for arduino-cli libraries:
    export ARDUINO_CLI_DIR=${HOME}/Arduino
  4. Execute tests:
    make -C src/ make_all && make -C src/ runtests

About

Clock with flexible second time driven by rotary encoder

Resources

Stars

Watchers

Forks

Packages

No packages published