Hello, I am just starting to work with the Ardunio Uno Rev 3 hardware and re-learning programing; programing experience is from TI 99/4A Extend Basic days!
I am working with the Arduio Uno example sketch from the RTCLib, DS1307.
Here is what I have so far:
//Arduino 1.0+ Only
//Arduino 1.0+ Only
// Modified DDT DS1307 RTC.ino
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
void setup(){
Wire.begin();
Serial.begin(9600);
setDateTime(); //MUST CONFIGURE IN FUNCTION
}
void loop(){
switch(Minute);
printDate();
delay(1000);
}
void setDateTime(){
byte second = 00; //0-59
byte minute = 13; //0-59
byte hour = 8; //0-23
byte weekDay = 6; //1-7
byte monthDay = 07; //1-31
byte month = 12; //1-12
byte year = 12; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Switch(minute);
Serial.print(":");
Serial.println(second);
}
void Switch(minute){ // Print only every 15 minutes EG 3/1/11 23:00:00, 23:15:00, 23:30:00, 23:45:00
Case 1;
if (minute) = 00;
Serial.print(minute);
break;
Case 2;
if (minute) = 15;
Serial.print(minute);
break;
Serial.print(minute);
Case 3;
if (minute) = 30;
Serial.print(minute);
break;
Case 4;
if (minute) = 45;
Serial.print(minute)
break;
Default;
break;
}
Verifing the sketch; I have the following errors:
sketch_dec08a:15: error: variable or field 'Switch' declared void
sketch_dec08a:15: error: 'minute' was not declared in this scope
sketch_dec08a.ino: In function 'void loop()':
sketch_dec08a:17: error: 'Minute' was not declared in this scope
sketch_dec08a.ino: In function 'void printDate()':
sketch_dec08a:87: error: 'Switch' was not declared in this scope
sketch_dec08a.ino: At global scope:
sketch_dec08a:93: error: variable or field 'Switch' declared void
sketch_dec08a:93: error: 'minute' was not declared in this scope
Please, could someone help to debug this sketch?
Thank you.