Untitled
unknown
c_cpp
4 years ago
2.5 kB
6
Indexable
/* Example sketch to control a 28BYJ-48 stepper motor with ULN2003 driver board and Arduino UNO. More info: https://www.makerguides.com */
#include <Wire.h>
#include "RTClib.h"
#include <Stepper.h>
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
// Define number of steps per rotation:
const int stepsPerRevolution = 2048;
// Wiring:
// Pin 8 to IN1 on the ULN2003 driver
// Pin 9 to IN2 on the ULN2003 driver
// Pin 10 to IN3 on the ULN2003 driver
// Pin 11 to IN4 on the ULN2003 driver
// Create stepper object called 'myStepper', note the pin order:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC lost power, lets set the time!");
// Comment out below lines once you set the date & time.
// Following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// Following line sets the RTC with an explicit date & time
// for example to set January 27 2017 at 12:56 you would call:
// rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));
}
// Set the speed to 5 rpm:
myStepper.setSpeed(10);
// Begin Serial communication at a baud rate of 9600:
Serial.begin(9600);
DateTime now = rtc.now();
int mins = now.minute();
uint32_t steps = ((uint32_t)mins * 2048) / 60;
Serial.print("mins: ");
Serial.println(mins, DEC);
Serial.print("steps: ");
Serial.println(steps);
int stepdo = (int)steps;
Serial.println(stepdo);
myStepper.step(stepdo);
}
void loop() {
#if 0
Serial.print(now.year(), DEC);
Serial.print(" / ");
Serial.print(now.month(), DEC);
Serial.print(" / ");
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");
Serial.println();
Serial.println();
#endif
// Step one revolution in one direction:
myStepper.step(10);
delay(1000);
}
Editor is loading...