Ok, right, this is the problem...
If I wanted to switch something on my arm would do what my brain wanted, I dont have to code my brain....
I get that people may know how to do this, and all this makes sense, but I have only just got this thing, and as much as I want to try as much as I can, Im stumped.
I've tried cutting about various examples from the universal KB, however nothing ties in to what I am trying to get, or does it work, this is why IUm after some help, from somone who will probably now this very quick, and be willing to help me out, wihtout sounding rude, everyone starts somewhere, so turning the question back with another question isn't really that helpfull...
So here I am...
I have the RTC on, it works, I have the LCD on it works, I have the relays hooked up, and yes albeit on a weird timing, they work...
This is where I am stuck, can somone please help me out here, as said, all Im trying to do is get 1 example that works with what I have to turn relay0pin on at x time and off at y time...
I will want expandability to the 4 relays, but thats the bit I'll work out, I just need the first one to help me on my way.... This is where I am so far....
//LCD Realy test 1.2.0.3 //Arduino SYNCS with RTC
#include <LiquidCrystal.h>
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#include <Time.h>
#include <DS1307RTC.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
const int relay0pin = 6;
const int relay1pin = 7;
const int relay2pin = 8;
const int relay3pin = 9;
int relay0state = LOW;
int relay1state = LOW;
int relay2state = LOW;
int relay3state = LOW;
long previousMillis0 = 1; // will store last time relay0 was updated
long previousMillis1 = 1; // will store last time relay1 was updated
long previousMillis2 = 1; // will store last time relay1 was updated
long previousMillis3 = 1; // will store last time relay1 was updated
long interval0 = 400; // interval at which to switch (milliseconds)
long interval1 = 800; // interval at which to switch (milliseconds)
long interval2 = 1600; // interval at which to switch (milliseconds)
long interval3 = 3200; // interval at which to switch (milliseconds)
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void setDateDs1307(byte second,
byte minute,
byte hour,
byte dayOfWeek,
byte dayOfMonth,
byte month,
byte year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second));
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);
Wire.endTransmission();
}
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
*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()
{
pinMode(relay0pin, OUTPUT);
pinMode(relay1pin, OUTPUT);
pinMode(relay2pin, OUTPUT);
pinMode(relay3pin, OUTPUT);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
Serial.begin(9600);
second = 00;
minute = 00 ;
hour = 18;
dayOfWeek = 7;
dayOfMonth = 20;
month = 4;
year = 13;
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
lcd.begin(16, 2); // tells Arduino the LCD dimensions
Serial.begin(9600);
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");}
void loop()
{{
lcd.begin(16, 2);
lcd.setCursor(11, 0);
lcd.print("Light");
lcd.setCursor (11,1);
lcd.print("*");
if (relay0state == HIGH)
{
lcd.setCursor(12,2);
lcd.print("*");
}
if (relay1state == HIGH)
{
lcd.setCursor(13,2);
lcd.print("*");
}
if (relay2state == HIGH)
{
lcd.setCursor(14,2);
lcd.print("*");
}
if (relay3state == HIGH)
{
lcd.setCursor(15,2);
lcd.print("*");
}
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.setCursor(0,0);
if (hour<10)
{
lcd.print("0");
}
lcd.print(hour, DEC);
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
if (second<10)
{
lcd.print("");
}
lcd.setCursor(0,1);
switch(dayOfWeek)
{
case 1:
lcd.print("Sun");
break;
case 2:
lcd.print("Mon");
break;
case 3:
lcd.print("Tue");
break;
case 4:
lcd.print("Wed");
break;
case 5:
lcd.print("Thu");
break;
case 6:
lcd.print("Fri");
break;
case 7:
lcd.print("Sat");
break;
}
delay(250);
}
unsigned long currentMillis0 = millis();
unsigned long currentMillis1 = millis();
unsigned long currentMillis2 = millis();
unsigned long currentMillis3 = millis();
if(currentMillis0 - previousMillis0 > interval0)
{
previousMillis0 = currentMillis0;
if (relay0state == LOW)
relay0state = HIGH;
else
relay0state = LOW;
digitalWrite(relay0pin, relay0state);
}
if(currentMillis1 - previousMillis1 > interval1)
{
previousMillis1 = currentMillis1;
if (relay1state == LOW)
relay1state = HIGH;
else
relay1state = LOW;
digitalWrite(relay1pin, relay1state);
}
if(currentMillis2 - previousMillis2 > interval2)
{
previousMillis2 = currentMillis2;
if (relay2state == LOW)
relay2state = HIGH;
else
relay2state = LOW;
digitalWrite(relay2pin, relay2state);
}
if(currentMillis3 - previousMillis3 > interval3)
{
previousMillis3 = currentMillis3;
if (relay3state == LOW)
relay3state = HIGH;
else
relay3state = LOW;
digitalWrite(relay3pin, relay3state);
}
if(Serial.available())
{
time_t t = processSyncMessage();
if(t >0)
{
RTC.set(t); // set the RTC and the system time to the received value
setTime(t);
}
}
digitalClockDisplay();
// delay(1000);
}
void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
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.print('0');
Serial.print(digits);
}
/* code to process time sync messages from the serial port */
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 'T' // Header tag for serial time sync message
time_t processSyncMessage() {
// return the time if a valid sync message is received on the serial port.
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
char c = Serial.read() ;
Serial.print(c);
if( c == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
c = Serial.read();
if( c >= '0' && c <= '9'){
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
return pctime;
}
}
return 0;
}
Obviously this timer bit I'm after will replace my test of (which can be disreagarded).