Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <RTClib.h>
#include <PGMWrap.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
RTC_DS3231 rtc;
uint16_p servoMap0[] PROGMEM = {448, 411, 375, 342, 309, 275, 242, 210, 178, 148};
uint16_p servoMap1[] PROGMEM = {524, 481, 441, 402, 361, 322, 282, 244, 206, 169};
uint16_p servoMap2[] PROGMEM = {544, 497, 456, 414, 370, 328, 288, 250, 210, 175};
uint16_p servoMap3[] PROGMEM = {437, 400, 368, 335, 303, 269, 236, 204, 174, 143};
void setup() {
Serial.begin(115200);
rtc.begin();
if (rtc.lostPower())
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
}
void loop() {
DateTime now = rtc.now();
//uint16_t number = now.minute() * 100 + now.second();
uint16_t number = now.hour() * 100 + now.minute();
setServoPositions(number);
delay(100);
}
void setServoPositions(uint16_t number) {
pwm.setPWM(0, 0, servoMap0[((number/1000)%10)]);
pwm.setPWM(1, 0, servoMap1[((number/100)%10)]);
pwm.setPWM(2, 0, servoMap2[((number/10)%10)]);
pwm.setPWM(3, 0, servoMap3[((number/1)%10)]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment