I guess i will save the "flip-project" for later, kind of upgrading the clock.
so for now i will stick with servos, i dont know how to multiplex, so i will use an arduino mega board ( i can use up to 48 servos ) i wrote this code for running the hole thing :
// include libraries
#include "Wire.h"
#include "Servo.h"
Servo *hourServos[] = {hour_servo1, hour_servo2, hour_servo3, hour_servo4, hour_servo5, hour_servo6, hour_servo7, hour_servo8, hour_servo9, hour_servo10, hour_servo11, hour_servo12, hour_servo13, hour_servo14};
Servo *min_ten_Servos[] = {min_ten_servo1, min_ten_servo2, min_ten_servo3, min_ten_servo4, min_ten_servo5, min_ten_servo6, min_ten_servo7, min_ten_servo8, min_ten_servo9, min_ten_servo10, min_ten_servo11, min_ten_servo12, min_ten_servo13, min_ten_servo14};
Servo *min_one_Servos[] = {min_one_servo1, min_one_servo2, min_one_servo3, min_one_servo4, min_one_servo5, min_one_servo6, min_one_servo7, min_one_servo8, min_one_servo9, min_one_servo10, min_one_servo11, min_one_servo12, min_one_servo13, min_one_servo14};
#define DS1307_I2C_ADDRESS 0x68
// defining variables
int realhour = 0;
int hours = 0;
int minutes = 0;
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
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.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.send(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
}
void getDateDs1307(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month,byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f);
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
// Function to Set time
/////
/////
////
/////
void setup() {
hour_servo1.attach(1);
hour_servo2.attach(2);
hour_servo3.ttach(3);
hour_servo4.attach(4);
hour_servo5.attach(5);
hour_servo6.attach(6);
hour_servo7.attach(7);
hour_servo8.attach(8);
hour_servo9.attach(9);
hour_servo10.attach(10);
hour_servo11.attach(11);
hour_servo12.attach(12);
hour_servo13.attach(13);
hour_servo14.attach(14);
min_ten_servo1.attach(1);
min_ten_servo2.attach(2);
min_ten_servo3.attach(3);
min_ten_servo4.attach(4);
min_ten_servo5.attach(5);
min_ten_servo6.attach(6);
min_ten_servo7.attach(7);
min_ten_servo8.attach(8);
min_ten_servo9.attach(9);
min_ten_servo10.attach(10);
min_ten_servo11.attach(11);
min_ten_servo12.attach(12);
min_ten_servo13.attach(13);
min_ten_servo14.attach(14);
min_one_servo1.attach(1);
min_one_servo2.attach(2);
min_one_servo3.attach(3);
min_one_servo4.attach(4);
min_one_servo5.attach(5);
min_one_servo6.attach(6);
min_one_servo7.attach(7);
min_one_servo8.attach(8);
min_one_servo9.attach(9);
min_one_servo10.attach(10);
min_one_servo11.attach(11);
min_one_servo12.attach(12);
min_one_servo13.attach(13);
min_one_servo14.attach(14);
second = 0;
dayOfWeek = 1;
dayOfMonth = 24;
month = 5;
year = 10;
// Set up the time using the buttons then ->
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}
void loop() {
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
realhour = int(hour);
if (realhour==0) // if it is 0000h, that should be 1200h in 12 hour time
{
realhour=12;
}
if (hour>=13)
{
realhour=realhour-12; // convert 24h hours to 12h hours
}
hours=realhour*14;
minutes=minute*3;
minute_ten = minutes/10;
minute_one = minutes%10;
// hours case from 1 - 12
// minute_ten from 1 - 5
// minute_one from 1 - 9
switch(hours) {
case '1':
hourServos[1].write(45);; // if active set position to 45 degree
hourServos[2].write(0);; // if inactive set position to 0 degree
break;
case '2':
.
.
.
.
case '12':
.
break;
}
delay(100); // servos need time to move
switch(minutes) {
case '1':
.
break;
case '2':
.
.
.
.
case '60':
.
break;
}
delay(100);
}
1 ) - i have problems setting time with buttons ... i cant figure out how to do it ?
it is specially, how can can get the servos to react when sitting the time .. so can visualize the time setting ( if that made sense )
any suggestions on how to do it ?