hai sir,
i am using a 3 led(RED, YELLOW, GREEN), ARDUINO board and REAL TIME CLOCK
i am using the
http://www.dfrobot.com/index.php?route=product/product&filter_name=real%20time%20clock&product_id=511
i want try to make LED blinking according to the time range
i have 3 led:
RED led; it will on only from 1 a.m to 2a.m
YELLOW led; it will on only from 2 a.m to 3a.m
GREEN led; it will on only from 3 a.m to 4a.m
my problem is i dont know how to make the range in the coding..
how to write this range for the command??
i hope u can help me figure this out
i had edit the code from the autofeeder coding..
http://www.robothead2toe.com.my/download/Vol.%2011/Download%20for%20Vol%2011%20Dec11.zip
and this is what i had made..
this coding has working when i running it on arduino.. and i make the led blinking for 5sec.. but how to make it blinking according to the time range??
#include <Wire.h>
#include "RTClib.h"
// Assign LED to digital pin 13
const int LED = 13;
const int LED2= 12;
const int LED3= 11;
// Flag for entering LED routines
uint8_t flag = 1;
uint8_t flag2 = 1;
uint8_t flag3 = 1;
// Create RTC object
RTC_DS1307 RTC;
// Set alarm to activate two times a day
byte HOUR1 = 00, MINUTE1 = 21;
byte HOUR2 = 00, MINUTE2 = 22;
byte HOUR3 = 00, MINUTE3 = 23;
void setup ()
{
pinMode(LED,OUTPUT); // LED pin as output
digitalWrite(LED,LOW); // Turn off LED by default
pinMode(LED2,OUTPUT); // LED pin as output
digitalWrite(LED2,LOW); // Turn off LED by default
pinMode(LED3,OUTPUT); // LED pin as output
digitalWrite(LED3,LOW); // Turn off LED by default
Serial.begin(57600); // Initialize serial & set baudrate
Wire.begin(); // Initialize I2C 2 wires interface
RTC.begin(); // Initialize DS1307 RTC chip
if (! RTC.isrunning()) // If RTC is not running, set the time
{
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop ()
{
// Read current time from RTC chip
DateTime now = RTC.now();
// Send current time to serial for debugging
Serial.print(now.year(),DEC);
Serial.print('/');
Serial.print(now.month(),DEC);
Serial.print('/');
Serial.print(now.day(),DEC);
Serial.print(' ');
Serial.print(now.hour(),DEC);
Serial.print(':');
Serial.print(now.minute(),DEC);
Serial.print(':');
Serial.print(now.second(),DEC);
Serial.println();
// led red
if(((now.hour()==HOUR1)&&(now.minute()==MINUTE1)))
{
if(flag == 1)
{
Serial.print("RED");
Serial.println();
digitalWrite(LED,HIGH);
delay(5000); //delay for 1sec
flag = 0; // clear flag
delay(1000);
}
else
{
digitalWrite(LED,LOW);
}
}
// led yellow
if(((now.hour()==HOUR2)&&(now.minute()==MINUTE2)))
{
if(flag2 == 1)
{
Serial.print("Yellow");
Serial.println();
digitalWrite(LED2,HIGH);
delay(5000); //delay for 1sec
flag2 = 0; // clear flag
delay(1000);
}
else
{
digitalWrite(LED2,LOW);
}
}
// led green
if(((now.hour()==HOUR3)&&(now.minute()==MINUTE3)))
{
if(flag3 == 1)
{
Serial.print("GREEN");
Serial.println();
digitalWrite(LED3,HIGH);
delay(5000); //delay for 1sec
flag3 = 0; // clear flag
delay(1000);
}
else
{
digitalWrite(LED3,LOW);
}
}
}