I have been playing with the Binary Clock featured in the Evil Genius book.
Had a problem with running too slow so I attached a RTC to A4 and A5 for time reading.
I would like the time adjust button (moved from pin 18 to pin 11) to step the minutes forward and reset the seconds to 0 and then set this as the new time in the RTC. I cannot get this to work. I also added in a serial printout so I can view the time while plugged in. Below is my coding… Any suggestion on setting time forward, resetting seconds, and writing to RTC?
// Lilypad binary clock - Set using RTC
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
int switchPin = 11;
int hourLEDs = {4, 3, 2, 1}; // least sigificant bit frst
int secondLEDs = {10, 9, 8, 7, 6, 5};
int minuteLEDs = {17, 16, 15, 14, 13, 12};
int loopLEDs = {10, 9, 8, 7, 6, 5, 17, 16, 15, 14, 13, 12, 1, 2, 3, 4};
void setup()
{
for (int i = 0; i < 4; i++)
{
pinMode(hourLEDs*, OUTPUT);*
- }*
- for (int i = 0; i < 6; i++)*
- {*
_ pinMode(minuteLEDs*, OUTPUT);_
_ }_
_ for (int i = 0; i < 6; i++)_
_ {_
_ pinMode(secondLEDs, OUTPUT);
}_
time_t t = now();
_ setSyncProvider(RTC.get); // the function to get the time from the RTC*
* Serial.begin(9600);*_
}
*void loop() *
{
* if (digitalRead(switchPin))*
* {*
* //RTC.set(time_t);
_ //adjustTime(60);
// delay(100);
//second() == 0;
//spin(hour());
//setTime(t)*_
* }*
* else if (minute() == 0 && second() == 0)*
* {*
* spin(hour());*
* }*
* updateDisplay();*
* delay(1);*
}
void updateDisplay()
{
* setSyncProvider(RTC.get);*
* time_t t = now();
_ setOutput(hourLEDs, 4, hourFormat12(t));
setOutput(minuteLEDs, 6, minute(t));
setOutput(secondLEDs, 6, second(t));*_
* Serial.print(hour());*
* printDigits(minute());*
* printDigits(second());*
* 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);*
}
void setOutput(int *ledArray, int numLEDs, int value)
{
* for (int i = 0; i < numLEDs; i++)*
* {*
_ digitalWrite(ledArray*, bitRead(value, i));
}*_
}
void spin(int count)
{
* for (int i = 0; i < count; i++)*
* {*
* for (int j = 0; j < 16; j++)*
* {*
* digitalWrite(loopLEDs[j], HIGH);*
* delay(50);*
* digitalWrite(loopLEDs[j], LOW);*
* }*
* }*
}