-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfull
More file actions
62 lines (48 loc) · 1.4 KB
/
full
File metadata and controls
62 lines (48 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_PWMServoDriver.h>
RTC_PCF8523 rtc;
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
const int SERVO_CHANNEL = 1;
const int SERVO_CHANNEL2 = 4;
const int MIN_PULSE_WIDTH = 100;
const int MAX_PULSE_WIDTH = 550;
void setup() {
// Initialize the I2C bus on A4 and A5
Serial.begin(9600);
Wire.begin();
// Initialize the RTC on A4 and A5
// Initialize the PCA9685 on A4 and A5 with address 0x41
pwm.begin();
rtc.begin();
// Set the PWM frequency to 50 Hz
pwm.setPWMFreq(50);
}
void loop() {
// Read the time and date from the RTC
DateTime now = rtc.now();
// Print the time and date to the serial monitor
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
// Wait for one second before reading the time and date again
delay(1000);
// Set the pulse width to the minimum value
pwm.setPWM(SERVO_CHANNEL, 0, (100+7*(now.second())));
//delay(500);
pwm.setPWM(SERVO_CHANNEL2, 0, (100+7*(now.second())));
//delay(500);
// Set the pulse width to the maximum value
//pwm.setPWM(SERVO_CHANNEL, 0, 400);
//delay(500);
//pwm.setPWM(SERVO_CHANNEL2, 0, 400);
}