Step 3Code Structure
void loop()
{
clock(); // keep track of time, i.e. update hours, minutes and seconds variables as needed.
display(); // display the time, or the alarm time, depending on the state of the settings switch.
alarm(); // checks if it's time for the alarm to start.
update_buttons_state(); // checks if the buttons and touch sensor states has changed
buttons(); // does what the buttons should do
}
The variables that are needed by several functions are declared in the first tab (where setup() and loop() is) and the variables that are needed only by one function is declared in the same tab as that function.
If you change the DEBUG constant to 1 you will get some output via serial that can be good for troubleshooting, e.g. the time and what value the touchsensor returns.
I have tried to comment and make the code understandable but if you have questions or suggestions for improvements just leave a comment.
Here are the pins I used for the different parts:
- 2 and 4: Touchsensor (4 is the send pin, 2 is recieve)
- 6 Hour button
- 5 Minute button
- 7 Switch
- 14-18 Display hour pins
- 8-13 Display minute pins
You can use whatever pins you want, just change in the code accordingly.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|
















































