Pages: [1] 2   Go Down
Author Topic: digitalWrite - alarmRepeat  (Read 1176 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use timealarms to control led light (42w). I use 17 alarm.Repeat per day.
In test mode(1minute) everything works fine, but in 24h cycle it stops working correctly.

To avoid power failure problems is after every hour alarm.Repeat digitalWrite(HIGH) or LOW for relays.
I think this is problem.

Code:

#include <DS1307RTC.h>
#include <Time.h>
#include <TimeAlarms.h>  // accepts 23 alarmRepeat
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int MW = 6;        //leds power supply (relay on / off)
const int W = 9;        //white led (relay ON /off)  
const int BLUE = 10;         //blue led PWM module (PWM or withoutPWM 100%)

LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
 Serial.begin(9600);
 //setTime(9,29,55,12,30,12);      // TEST


  setSyncProvider(RTC.get);   // the function to get the time from the RTC
    if(timeStatus()!= timeSet)
       Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time");

  lcd.init(); // initialize the lcd
  lcd.backlight();
  lcd.setCursor(0, 1);
  lcd.print("RESTART");
  
  pinMode (MW, OUTPUT);
  pinMode (W, OUTPUT);
  pinMode (BLUE, OUTPUT);
  
  digitalWrite(MW, HIGH);      //power supply OFF
  digitalWrite(W, HIGH);      //white leds OFF
  
  // ***** TEST ****
  /*
  Alarm.alarmRepeat(9,30,00, H06M30);        
  Alarm.alarmRepeat(9,30,05, H07M30);      
  Alarm.alarmRepeat(9,30,10, H08M30);        
  Alarm.alarmRepeat(9,30,15, H10M30);        
  Alarm.alarmRepeat(9,30,20, H10M30);        
  Alarm.alarmRepeat(9,30,25, H11M30);        
  Alarm.alarmRepeat(9,30,30, H12M30);        
  Alarm.alarmRepeat(9,30,35, H13M30);        
  Alarm.alarmRepeat(9,30,40, H14M30);        
  Alarm.alarmRepeat(9,30,44, H15M30);        
  Alarm.alarmRepeat(9,30,50, H16M30);        
  Alarm.alarmRepeat(9,30,55, H17M30);        
  Alarm.alarmRepeat(9,31,05, H18M30);        
  Alarm.alarmRepeat(9,31,10, H19M30);        
  Alarm.alarmRepeat(9,31,15, H20M30);      
  Alarm.alarmRepeat(9,31,20, H21M30);        
  Alarm.alarmRepeat(9,31,25, H22M30);      
  Alarm.alarmRepeat(9,31,30, H23M30);      
  */
  
  ///LED control times        
                  
  Alarm.alarmRepeat(6,30,00, H06M30);        
  Alarm.alarmRepeat(7,30,05, H07M30);        
  Alarm.alarmRepeat(8,30,10, H08M30);        
  Alarm.alarmRepeat(9,30,15, H09M30);      
  Alarm.alarmRepeat(10,30,20, H10M30);        
  Alarm.alarmRepeat(11,30,25, H11M30);        
  Alarm.alarmRepeat(12,30,30, H12M30);        
  Alarm.alarmRepeat(13,30,35, H13M30);        
  Alarm.alarmRepeat(14,30,40, H14M30);        
  Alarm.alarmRepeat(15,30,44, H15M30);        
  Alarm.alarmRepeat(16,30,50, H16M30);        
  Alarm.alarmRepeat(17,30,55, H17M30);        
  Alarm.alarmRepeat(18,31,05, H18M30);      
  Alarm.alarmRepeat(19,31,10, H19M30);        
  Alarm.alarmRepeat(20,31,15, H20M30);      
  Alarm.alarmRepeat(21,31,20, H21M30);        
  Alarm.alarmRepeat(22,31,25, H22M30);        
  Alarm.alarmRepeat(23,31,30, H23M30);      
  
}

void loop() {
  digitalClockDisplay();
  Alarm.delay(1000);
  
}
  
void H06M30() {                            
  Serial.println("BLUE 33% WHITE 00% POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B33% W00% P ON ");
  analogWrite(BLUE, 84);        // blue leds 33%
  digitalWrite(MW, LOW);        // power supply ON
  digitalWrite(W, HIGH);        // white leds OFF
 }
  
 void H07M30() {                            
  Serial.println("BLUE 33% WHITE 00% POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B33% W00% M ON ");
  analogWrite(BLUE, 84);          
  digitalWrite(MW, LOW);          
  digitalWrite(W, HIGH);          
 }
 
void H08M30() {                            
  Serial.println("BLUE 66% WHITE 00% POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B66% W00% M ON ");  
  analogWrite(BLUE, 168);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);
 }
 
void H09M30() {                            
  Serial.println("BLUE 100% WHITE OFF POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W00% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);
  
 }  

void H10M30() {                            
  Serial.println("BLUE 100% WHITE OFF POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W00% M ON ");  
  analogWrite(BLUE, 255);
 digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);
 }  
 
void H11M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON ");
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);                // white leds on
 }

void H12M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 }
void H13M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);
 }

void H14M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);
 }  

void H15M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 }  

void H16M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 }

void H17M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 }

void H18M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 }

void H19M30() {                            
  Serial.println("BLUE 100% WHITE OFF POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B100% W00% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);        //white leds OFF
 }

void H20M30() {                            
  Serial.println("BLUE 66% WHITE OFF POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B66% W00% M ON ");  
  analogWrite(BLUE, 168);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);
 }


void H21M30() {                            
  Serial.println("BLUE 33% WHITE OFF POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("B33% W00% M ON ");  
  analogWrite(BLUE, 84);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);
  
 }
void H22M30() {                            
  Serial.println("BLUE 33% WHITE OFF POWER ON");
  lcd.setCursor(0, 1);
  lcd.print("BS33% W00% M ON ");    
  analogWrite(BLUE, 84);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);  
 }

void H23M30() {                            
  Serial.println("BLUE OFF WHITE OFF POWER OFF");
  lcd.setCursor(0, 1);
  lcd.print("....GOOD BYE....");
  digitalWrite(BLUE, LOW);       // blue OFF
  digitalWrite(MW, HIGH);        // power supply OFF
  digitalWrite(W, HIGH);         // white leds OFF

  
 }
 
void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
  lcd.setCursor(0, 0);
  lcd.print(hour());
  LCDprintDigits(minute());
  LCDprintDigits(second());
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void LCDprintDigits(int LCDdigits)
{
  lcd.print(":");
  if(LCDdigits < 10)
    Serial.print('0');
  lcd.print(LCDdigits);
}
« Last Edit: January 25, 2013, 03:41:31 pm by oringo » Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oringo,

I'm pretty sure someone here can help you, maybe even me!

But to do that we need to see your whole sketch.  Be sure and post it between code tags ( the # button above the test edit box).

The code you posted was "way" not enough to tell what your problem is.

Cheers,
John
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I add whole sketch.
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4018
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unless you have changed this line in TimeAlarms.h the maximum number of alarms that can be active is 6

Code:
#define dtNBR_ALARMS 6   // max is 255

Have you changed it ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have modified it up to 40.

"Time.h"
#define dtNBR_ALARMS 40

 
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4018
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Incidentally, you have an insane number of functions in that code all doing basically the same thing.  There are a number of ways to reduce the number of functions but the easiest to understand would be to have one function and to call it with parameters.

Code:
void showState(char serial.Message, char lcdMessage, int blueValue, int MWValue, int WValue)
{
  Serial.println(serial.Message);
  lcd.setCursor(0, 1);
  lcd.print(lcd.Message); 
  analogWrite(BLUE, blueValue);
  digitalWrite(MW, MWValue);
  digitalWrite(W, WValue); 
}
Then at 18:30 call it like this :
Code:
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);

and at 19:30 like this :
Code:
showState("BLUE 100% WHITE OFF POWER ON","B100% W00% M ON ",255,0,255);

You could have the function construct the text shown based on the values sent to remove the need to send the text explicitly and save space
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you! idea is good and simple. smiley

I add your sketch and i get error
invalid conversion from "const char*" to "char"

I am beginner.
What i must add more to sketch?
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use timealarms to control led light (42w). I use 17 alarm.Repeat per day.
In test mode(1minute) everything works fine, but in 24h cycle it stops working correctly.

Do you mean that the it works properly throughout the first day but then the next day at 6:30 am it doesn't work?

For the "const char *" error I think for now you can just change

Code:
from this:
void showState(char serial.Message, char lcdMessage, int blueValue, int MWValue, int WValue)
to this:
void showState(const char* serialMessage, const char* lcdMessage, int blueValue, int MWValue, int WValue)

(there are some other issues but try this first)

John
« Last Edit: January 26, 2013, 09:18:30 am by johncc » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4018
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, my fault for doing things in a hurry.

The function declaration should be

Code:
void showState(char* serialMessage, char* lcdMessage, int blueValue, int MWValue, int WValue)
{
  Serial.println(serialMessage);
  lcd.setCursor(0, 1);
  lcd.print(lcdMessage); 
  analogWrite(BLUE, blueValue);
  digitalWrite(MW, MWValue);
  digitalWrite(W, WValue); 
}
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12534
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

void showState(const char* serial.Message, const char* lcdMessage, int blueValue, int MWValue, int WValue)

That doesn't look right to me.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, but I'm blaming UKHeliBob for that one smiley

edited/fixed, thanks
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4018
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will gladly take the blame as it was originally wrong in more ways than one.

Is it right now though I ask myself (and others) ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12534
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The argument types don't exactly match the signatures for analogWrite() and digitalWrite(), but I don't suppose we're too concerned about type safety here.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I hear that, I still keep wanting digitalWrite to be digitalWrite(int, bool), but Mr. Nick has convinced me to "get over it" smiley

Cheers,
John
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you mean that the it works properly throughout the first day but then the next day at 6:30 am it doesn't work?

24 hours is ok, but 48 hours then it like stops and keeps old values. Short test it works correctly.

Thank you! New sketch looks nice and still is simple.
Code:

#include <DS1307RTC.h>
#include <Time.h>
#include <TimeAlarms.h>  // accepts 23 alarmRepeat
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int MW = 6;        //leds power supply (relay on / off)
const int W = 9;        //white led (relay ON /off) 
const int BLUE = 10;         //blue led PWM module (PWM or withoutPWM 100%)



LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
 Serial.begin(9600);
 setTime(9,29,55,12,30,12);      // TEST

/*
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
    if(timeStatus()!= timeSet)
       Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time");
*/

  lcd.init(); // initialize the lcd
  lcd.backlight();
  lcd.setCursor(0, 1);
  lcd.print("RESTART");
 
  pinMode (MW, OUTPUT);
  pinMode (W, OUTPUT);
  pinMode (BLUE, OUTPUT);
 
  digitalWrite(MW, HIGH);      //power supply OFF
  digitalWrite(W, HIGH);      //white leds OFF
 
  // ***** TEST ****
 
  Alarm.alarmRepeat(9,30,00, H06M30);       
  Alarm.alarmRepeat(9,30,05, H07M30);       
  Alarm.alarmRepeat(9,30,10, H08M30);       
  Alarm.alarmRepeat(9,30,15, H10M30);       
  Alarm.alarmRepeat(9,30,20, H10M30);       
  Alarm.alarmRepeat(9,30,25, H11M30);       
  Alarm.alarmRepeat(9,30,30, H12M30);       
  Alarm.alarmRepeat(9,30,35, H13M30);       
  Alarm.alarmRepeat(9,30,40, H14M30);       
  Alarm.alarmRepeat(9,30,44, H15M30);       
  Alarm.alarmRepeat(9,30,50, H16M30);       
  Alarm.alarmRepeat(9,30,55, H17M30);       
  Alarm.alarmRepeat(9,31,05, H18M30);       
  Alarm.alarmRepeat(9,31,10, H19M30);       
  Alarm.alarmRepeat(9,31,15, H20M30);       
  Alarm.alarmRepeat(9,31,20, H21M30);       
  Alarm.alarmRepeat(9,31,25, H22M30);       
  Alarm.alarmRepeat(9,31,30, H23M30);       
 
 
  ///LED control times       
  /*                 
  Alarm.alarmRepeat(6,30,00, H06M30);       
  Alarm.alarmRepeat(7,30,05, H07M30);       
  Alarm.alarmRepeat(8,30,10, H08M30);       
  Alarm.alarmRepeat(9,30,15, H09M30);       
  Alarm.alarmRepeat(10,30,20, H10M30);       
  Alarm.alarmRepeat(11,30,25, H11M30);       
  Alarm.alarmRepeat(12,30,30, H12M30);       
  Alarm.alarmRepeat(13,30,35, H13M30);       
  Alarm.alarmRepeat(14,30,40, H14M30);       
  Alarm.alarmRepeat(15,30,44, H15M30);       
  Alarm.alarmRepeat(16,30,50, H16M30);       
  Alarm.alarmRepeat(17,30,55, H17M30);       
  Alarm.alarmRepeat(18,31,05, H18M30);     
  Alarm.alarmRepeat(19,31,10, H19M30);       
  Alarm.alarmRepeat(20,31,15, H20M30);       
  Alarm.alarmRepeat(21,31,20, H21M30);       
  Alarm.alarmRepeat(22,31,25, H22M30);       
  Alarm.alarmRepeat(23,31,30, H23M30);       
  */
}

void loop() {
  digitalClockDisplay();
  Alarm.delay(1000);

}

void showState(char* serialMessage,char* lcdMessage,int blueValue,int MWValue,int WValue)
{

  Serial.println(serialMessage);
  lcd.setCursor(0, 1);
  lcd.print(lcdMessage); 
  analogWrite(BLUE, blueValue);
  digitalWrite(MW, MWValue);
  digitalWrite(W, WValue); 
}
   
void H06M30() {                           
 showState("BLUE 33% WHITE OFF POWER ON","B33% WOFF M ON ", 85,0,1);
 }
 void H07M30() {                           
  showState("BLUE 33% WHITE OFF POWER ON","B66% WOFF M ON ", 85,0,1);           
 }
void H08M30() {                           
showState("BLUE 66% WHITE OFF POWER ON","B66% WOFF M ON ", 170,0,1);
 } 
void H09M30() {                           
showState("BLUE 66% WHITE OFF POWER ON","B66% WOFF M ON ",170,0,1);
 } 
void H10M30() {                           
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 } 
void H11M30() {                           
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }
void H12M30() {                           
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }
void H13M30() {                           
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }
void H14M30() {                           
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 } 
void H15M30() {                           
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 } 
void H16M30() {                           
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }
void H17M30() {                           
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }
void H18M30() {                           
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }
void H19M30() {                           
showState("BLUE 100% WHITE OFF POWER ON","B100% W OFF M ON ",255,0,1);
 }
void H20M30() {                           
showState("BLUE 66% WHITE OFF POWER ON","B100% W OFF M ON ",170,0,1);
 }
void H21M30() {                           
showState("BLUE 66% WHITE OFF POWER ON","B66% W OFF M ON ",170,0,1);
 }
void H22M30() {                           
showState("BLUE 33% WHITE OFF POWER ON","B66% W OFF M ON ",85,0,1);
 }
void H23M30() {                           
showState("BLUE OFF WHITE OFF POWER OFF","....GOOD BYE....",0,1,1);
 }
 
void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
  lcd.setCursor(0, 0);
  lcd.print(hour());
  LCDprintDigits(minute());
  LCDprintDigits(second());
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void LCDprintDigits(int LCDdigits)
{
  lcd.print(":");
  if(LCDdigits < 10)
    Serial.print('0');
  lcd.print(LCDdigits);
}
[/quote]
Logged

Pages: [1] 2   Go Up
Jump to: