Hello all,
i´m from germany and i had my last english lesson 35 y ago, but i try to explain a problem i have with a sketch to make a led blink:
since a few days i´m working with my new Arduino ( Mega 256 ) and i have tried out several simple sketches and they run well. But the following timeAlarm-Sketch does not work . The following code should turn on a led at 08:11:05 h at Pin 13 for 5 seconds. the sketch can be compiled and uploaded wothout problems.
After the program starts the clock is set to 08:11:00 h . time and date are shown correctly on the display ( 16 x 2 display )
The led is not turn on after 5 seconds. At pin 13 there are not 5 v after 5 seconds.
What is wrong?
Thanks for your help
safran
// Den Code habe ich hauptsächlich von (C)2010 Henning Karlsen
//
// web: Electronics - Henning Karlsen
// Die Code-Schnipsel für den Alarm habe ich mir im Net zusammengesucht
// A quick demo of how to use my DS1302-library to make a quick
// clock using a DS1302 and a 16x2 LCD.
#include <LiquidCrystal.h>
#include <DS1302.h>
#include <Time.h>
#include <TimeAlarms.h>
// Init the DS1302
DS1302 rtc(6,7,8);
int LED_Pin = 13;
// Init the LCD
LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
Serial.begin(9600);
// Setup LCD to 16x2 characters
lcd.begin(16, 2);
// The following lines can be commented out to use the values already stored in the DS1302
rtc.setDOW(SATURDAY); // Set Day-of-Week to Saturday
rtc.setTime(8, 11, 0); // Set the time to 08:11:00 (24hr format)
rtc.setDate(20, 4, 2013); // Set the date to April 20th, 2013
pinMode(LED_Pin, OUTPUT);
Alarm.alarmRepeat(8, 11, 5, MorningAlarm);
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));
lcd.setCursor(6, 0);
lcd.print(rtc.getDateStr());
Serial.println(rtc.getTimeStr());
// Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);
lcd.print(rtc.getTimeStr());
// Display date in the lower right corner
delay (1000);
}
//bei Aufruf des Alarms soll eine LED an Pin 13 für 5 Sekunden eingeschaltet werden
void MorningAlarm(){
digitalWrite(LED_Pin, HIGH);
delay(5000);
digitalWrite(LED_Pin, LOW);
}