top of page

The Clock



My mind started rushing with ideas when I first heard about this assignment. Of course, I didn't realize how hard it was going to be.


My usual creative process starts like this: dream big about all the possibilities, worry about implementation later.


Naturally, this project's premise manifested in many diverse ways. The first big idea I had was to create an alarm clock that dispensed marbles on top of a xylophone and trigger random sounds.


Idea #2 was to create an alarm clock that required users to make a physical gesture to snooze or dismiss.


 

The common denominator with these ideas was that simple controls were going to be used. Aside from all the fantasy-like ideas I can have sometimes, I am very interested in single input control.


I decided to venture and create a clock with a timer that users control with a simple encoder and finally use the LCD screen.


The features are the following:

  • Current time

  • Set time

  • Set alarm




Process


It was obvious that in order to be able to control so many different things about this clock with a simple input, context was very important: the screen or frame in which you are standing will determine the effect of the encoder.



I started by playing around with all the LCD examples available. They inspired me a lot, actually. After that, I made another standalone example with the encoders and understood the way they worked. Finally, I merged both into a single project and made sure to attach the Encoder to the Interrupt pins of the Arduino (An Arduino Uno was used for this due to the limitations in pins with the MKR series).





Different states are achieved from different places and inputs, so the after trial and error, the best way to achieve this was to implement a kind of state machine. This means that, according to some input and some conditions about the context, a global state variable would change. Then, the main loop would check against that and represent the visual and data aspects related to that state.


It was tricky to get right but it works.


The extra feature I wanted to include was a timer. I added another set of states and got a timer working with 5 second increments. The output is simply a piezo buzzer that gets dismissed when pressing down on the encoder.


The libraries used in this project are: Time, TimeAlarms, LiquidCrystalDisplay, Encoder, Bounce2



What worked


  • The state machine approach was perfect for this.

  • I created a utility function that converted encoder input to events such as ENCODER_UP, ENCODER_DOWN, ENCODER_PRESS to facilitate the operations and logic throughout the code.

  • The LCD screen is bright and very simple to manage.

  • The Time and TimeAlarm libraries are super nice.


What didn't work


  • The LCD screen keeps the previous String when you lcd.print() another text. I had to use lcd.clear() but the screen flickers.

  • A delay was needed to better space the encoder events. This in turn limits the response of the encoder in a bad way.


Key learnings


  • I need to brush up on my C/C++ skills. Im finding myself taking dirty shortcuts in my code and they are due to my lack of knowledge. (pointers...).

  • This needed more time than I anticipated.

  • RTC is cool, but for simple stuff you can manage time manually and save on production costs.









Recent Posts

See All

HID

Introduction This one was a tough one. HID, or Human Interface Device, is any interface that allows us to control a computer of any kind. The USB HID class protocol is a standard that defines how comp

bottom of page