Hi there,
As i am having alot of waking up problems, I am creating an alarm. 8)
When alarm goes off the functions in ** alarm ** will be called. I then want to set alarmValue to true and use alarmSound to read alarmValue and make the noise/led burn/ complicated mechanism/ whatever. But i don't know hot to do this.
It goes wrong in lines 83-115
boolean alarmValue = false
pinmode alarmSound = pin 5 output
start
void(function te be called upon alarm)
- digitalwrite(boolean, true) (no succes)
- boolean = true (no succes)
/*
______ _ _____ ___ ___
|| || || /_\ |_ | |_ |___|
|| || || / \ _| | |__ | \
------------- CLOCK ---------------
*/
#include <Time.h>
#include <TimeAlarms.h>
#include <LiquidCrystal.h>
// ********************************************
// ********** PIN OUT *************************
// ********************************************
int light = 6; // The pin that the led is attached to (PWM)
int alarmSound = 5; // The pin that sets the alarm on (PWM)
int lightSensor = A0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //LiquidCrystal lcd(RS, E, D4, D5, D6, D7)
// *********************************************
// ********** VARIABLE *************************
// *********************************************
int brightness = 0; // how bright the LED is
int fadeSteps = 5; // how many points to fade the LED by at a time
int lightValue = 0;
boolean alarmValue = false; //false = alarm uit, true = alarm aan
// *********************************************
// ********** STATUS ***************************
// *********************************************
int lightThreshold = 100; // light threshold value at witch it switches, zie ook serial read
int fadeTime = 5000;
/*
Also the clock must be set to a time on or after Jan1 1971 when using the Alarm methods.
Timer methods are unchanged and will function even if the clock has not been set
*/
// ----------------------------------------------
// SETUP
// ----------------------------------------------
void setup() {
Serial.begin(9600);
pinMode(light, OUTPUT);
pinMode(alarmSound, OUTPUT);
pinMode(lightSensor, INPUT);
lcd.begin(16, 2); // lcd.begin(width, height); Initialize the display and set the size.
lcd.setCursor(1,1);
lcd.print("Tijd:");
setTime(9,59,55,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
// create the alarms
Alarm.alarmRepeat(9, 59, 58, MorningAlarm); // 8:30am every day
Alarm.alarmRepeat(17,45,0, EveningAlarm); // 5:45pm every day
Alarm.alarmRepeat(dowSaturday,8,30,30, WeeklyAlarm); // 8:30:30 every Saturday
Alarm.timerRepeat(15, Repeats); // timer for every 15 seconds
Alarm.timerOnce(10, OnceOnly); // called once after 10 seconds
}
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
// LOOP
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
void loop(){
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}
// *************** alarm ************************
// functions to be called when an alarm triggers:
void MorningAlarm(){
Serial.println("Alarm: - MorningAlarm");
alarmValue = true;
}
void EveningAlarm(){
Serial.println("Alarm: - turn lights on");
alarmValue = true;
}
void WeeklyAlarm(){
Serial.println("Alarm: - its Monday Morning");
alarmValue = true;
}
void ExplicitAlarm(){
Serial.println("Alarm: - this triggers only at the given date and time");
alarmValue = true;
}
void Repeats(){
Serial.println("15 second timer");
alarmValue == true;
}
void OnceOnly(){
Serial.println("This timer only triggers once");
if(alarmValue == false){
(alarmValue == true);
}}
void AlarmOn(){
if(alarmValue = true){
digitalWrite(alarmSound, HIGH);
}}
// *************** display ************************
void digitalClockDisplay(){
// digital clock display of the time
if(hour() < 10)
{
lcd.setCursor(7, 1);
}
else
{
lcd.setCursor(6, 1);
} //(x, y) Move the cursor to position (x, y). These are zero-based coordinates
lcd.print(hour());
if(minute() < 10)
{
lcd.setCursor(10, 1);
}
else
{
lcd.setCursor(9, 1);
}
lcd.print(minute());
if(second() < 10)
{
lcd.setCursor(13, 1);
}
else
{
lcd.setCursor(12, 1);
}
lcd.print(second());
}
void test()
{
lcd.setCursor(2,0);
lcd.print(alarmValue);
}