Wednesday, 13 January 2010


Step 1: keep time with on / off button.
Step 2: alarm to go off when hour and min is set, e.g. 7:30
Step 3: snooze

Step 1:To do this, i am using if statements with an anolog input.

The on / off button works by using this command:

// read the state of the set button value:
buttonSet = digitalRead(dayoff); // check if the dayoff button is pressed.

if (buttonSet == HIGH) { // if it has NOT been pressed, complete these steps
digitalWrite(ledgreen, HIGH); // turn green on:THIS IS TO ACT AS AN INDICACTOR!!

This still keeps time and can turn output off any time in code once pressed. This means my on / off button acts as setting the alarm and turning it off on signal. This is good as it means less buttons!!

Step 2: The tough part!

Changing the source; I've tried now, using LOTS of different codes to try and send the alarm signal to go off with an hour and min being specified.

The most affective so far is going back to my ' if else' statements.

if (hour == 8) {
digitalWrite(ledred, HIGH); // turn on red

This will reconise the hour, but using such commands as

if (hour ==8) { if (second ==10)} (seconds used as faster)
digitalWrite(ledred, HIGH); // turn on red

This sets the alarm to go off at 08:00:10 but at 08:00:11 it will come back on again...

if (hour ==8) { if (second >10)} (seconds used as faster)
digitalWrite(ledred, HIGH); // turn on red

This sets the alarm to go off at anything over 08:00:10 but it will come back on again at a new minute over 10 seconds 08:01:11...

I cannot get the alarm to go off indefinitely!

' If else' is good for hours
'case' is good for setting range

Step 3: Snooze

I couldn't get snooze working for some time. It did turn lights off once pressed but would not turn them back on after delay.

I had forgotten that i was using latching buttons, so to turn the lights back on, the switch had to be returned to its original position; lights turned off, delayed and came back on. Big lesson on the types of hardware you use!

The snooze is not working with real time tho! i seem unable to have 2 working buttons with time!

No comments:

Post a Comment