Light Controller Using Time Alarms... Alarms Not Declared

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
djjester611
 
Posts: 1
Joined: Thu Mar 08, 2012 4:59 pm

Light Controller Using Time Alarms... Alarms Not Declared

Post by djjester611 »

Sorry to all but this frustrating me in most ways.
Long n Skinny keeps showing that i haven't called for alarm. I am sure im missing something but cant see it.
I am using a DS3231sn but only works when coded as 1307 couldn't fig that one out. But its functioning great. I want my lights on at set times and off at set times. And i think the Alarms library will work great but no one uses it or understands it and they would rather have long strings instead of calling periodic times.

Take a gander and tell me what you think could be the problem?
P.S, i will attach a Notepad plus file for ease of opening

[Edit - moderator - please use the 'code' button when submitting code]

Code: Select all

#include <WProgram.h>
#include<Time.h>
#include<TimeAlarms.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal

// Pins to Control
unsigned long int mh = 11;
unsigned long int cfl = 9;

////////////////////////////////////////////////////
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  // Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void setup(){
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
Serial.begin(9600);
}
  {
  //Add our timers, and initialize
  Alarm.alarmRepeat(6,30,0, mhMorningAlarm);  // 6:30am every day
  Alarm.alarmRepeat(18,30,0,mhEvengingAlarm); // 6:35pm every day
  Alarm.alarmRepeat(6,30,0,cflMorningAlarm);  // 6:30am every day
  Alarm.alarmRepeat(18,30,0,cflEveningAlarm); // 6:35pm every day
  //Pin Mapping
  pinMode(mh, OUTPUT);
  pinMode(cfl, OUTPUT);
  //pinMode(pump1, OUTPUT);
  //pinMode(pump2, OUTPUT);
  
  }
}
void loop(){
{
  Alarm.delay(1000);
}
}
void mhMorningAlarm() //Finish defining our delegates
  {    digital.write(mh,HIGH) //switch on our relay, turning a pin high for example  
}
void mhMorningAlarm()
  {   digital.write(mh,LOW) //switch off our relay, turning a pin low for example 
}
void cflMorningAlarm() //Finish defining our delegates
  {    digital.write(cfl,HIGH) //switch on our relay, turning a pin high for example  
}
void cflMorningAlarm()
  {      digital.write(cfl,LOW) //switch off our relay, turning a pin low for example  
}
}
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
Serial.print(hour, DEC);// convert the byte variable to a decimal number when being displayed
Serial.print(":");
if (minute<10)

{
Serial.print("0");
}
Serial.print(minute, DEC);
Serial.print(":");
if (second<10)
{
Serial.print("0");
}
Serial.print(second, DEC);
Serial.print(" ");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print("  ");
switch(dayOfWeek){
case 1:
Serial.println("Sunday");
break;
case 2:
Serial.println("Monday");
break;
case 3:
Serial.println("Tuesday");
break;
case 4:
Serial.println("Wednesday");
break;
case 5:
Serial.println("Thursday");
break;
case 6:
Serial.println("Friday");
break;
case 7:
Serial.println("Saturday");
break;
}
{
// Serial.println(dayOfWeek, DEC);
delay(1000);
}
Attachments
DJ Jester Aquarium controller 11-19-12 v2.h
(4 KiB) Downloaded 181 times

dyslexic
 
Posts: 23
Joined: Sat Nov 24, 2012 2:40 am

Re: Light Controller Using Time Alarms... Alarms Not Declared

Post by dyslexic »

try this and run serial monitor and you should see the alarms turn on

Code: Select all

#include <stdlib.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>
#include <Wire.h>

/*-----( Declare Constants, Pin Numbers )-----*/
int mh = 11;
int cfl = 9;


  
  void setup(){
    Serial.begin(9600);
    
    //sync clock
  setSyncProvider(RTC.get); //function to get the time from the RTC
  if(timeStatus()!=BANNED){
    Serial.println("Unable to sync with the RTC");
  }
  else{
    Serial.println("RTC has set the system time");
  }
  
  pinMode(mh, OUTPUT);
  pinMode(cfl, OUTPUT);
  
  //Add our timers, and initialize
Alarm.alarmRepeat(6,30,0, mhMorningAlarm);  // 6:30am every day
Alarm.alarmRepeat(18,30,0,mhEveningAlarm); // 6:35pm every day
Alarm.alarmRepeat(6,30,0,cflMorningAlarm);  // 6:30am every day
Alarm.alarmRepeat(18,30,0,cflEveningAlarm); // 6:35pm every day

}

void loop(){

  digitalClockDisplay();  
  Alarm.delay(500); // wait one second between clock display  
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(month());
  Serial.print("/");
  Serial.print(day());
  Serial.print("/");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.println('0');
  Serial.print(digits);
}
// functions to be called when an alarm triggers:
void mhMorningAlarm(){
  digitalWrite(mh,HIGH);
  Serial.println("Turn On mh");    
}

void mhEveningAlarm(){
  digitalWrite(mh,LOW);
  Serial.println("Turn Off mh");  
}

void cflMorningAlarm(){
  digitalWrite(cfl,HIGH);
  Serial.println("Turn On cfl");
}

void cflEveningAlarm(){
  digitalWrite(cfl,LOW);
  Serial.println("Turn Off cfl");
} 

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”