function called activated boolean write

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);
}
  Alarm.alarmRepeat(9, 59, 58, MorningAlarm);                  // 8:30am every day

Might I suggest that you just buy an alarm clock? If you can't put meaningful comments in, at least keep the useless ones correct.

void AlarmOn(){
if(alarmValue = true){
    digitalWrite(alarmSound, HIGH);
  }}

Put each { on a new line, and ONE } per line. Then, explain why you are assigning true to alarmValue in that if statement.

if(alarmValue == false){
    (alarmValue == true);

Don't use brackets like that on the second line, they aren't necessary.

if(alarmValue = true){
    digitalWrite(alarmSound, HIGH);
  }}

PaulS is right about that. You are missing an "=" there.

Are you using a real-time clock here? I can't see any evidence of it, but without one I don't see how you can hope to set or maintain an accurate time. That seems like a fairly important requirement for an alarm clock.

What is the fun in buying an alarm clock? I thought this would be a good learning project for me. I indeed did not work very accurate there, but its not that important in that piece of code. As long as we understand it, right :wink:

I am using a library for the time

#include <Time.h>
#include <TimeAlarms.h>

If I set the alarmfunctions like this:

void Repeats(){
  Serial.println("15 second timer"); 
  digitalWrite(alarmSound, HIGH);

the led goes on when the alarm triggers the function. But how do I write alarmValue (boolean) to true?

void MorningAlarm(){
  Serial.println("Alarm: - MorningAlarm"); 
  alarmValue == true;  // doesnt work
}
void OnceOnly(){
  Serial.println("This timer only triggers once");  
  if(alarmValue == false){
    alarmValue == true; // doesnt work
}
}
void AlarmOn(){
if(alarmValue == true){
    digitalWrite(alarmSound, HIGH);
}
}

does the function "void Repeats(){" talk outside its own function, so to another function? (if a value is changed in void Repeats, can that value be read in void AlarmOn?)

dvdspelert:
alarmValue == true; // doesnt work

= is assignment
== is comparison

You need this general style:

if (a == b)  // compare (two == signs)
  c = d;     // assign (one = sign)

alarmValue == true; // doesnt work

It most certainly does. It simply doesn't do what you seem to think it does.