#include <UltraPing.h>
#include <Stepper.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <RTClib.h>
UltraPing my_sonar(3, 4);
Stepper my_stepper(200, 8, 9, 10, 11);
Adafruit_NeoPixel my_LED_strip(16, 12, NEO_GRB + NEO_KHZ800);
RTC_DS1307 rtc;
void setup() {
pinMode(13, INPUT);
rtc.begin();
// Set current date/time if required
if (rtc.isrunning()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
my_stepper.setSpeed(60);
my_LED_strip.begin();
}
void loop() {
if (rtc.now().hour() <= 24) {
my_LED_strip.fill(0xff0000);
my_LED_strip.show();
my_stepper.step(50);
while (!(my_sonar.ping_cm() < 80 || digitalRead(13) == HIGH)) {
delay(20);
}
my_LED_strip.fill(0x33ff33);
my_LED_strip.show();
my_stepper.step(-50);
while (!(my_sonar.ping_cm() > 80)) {
delay(20);
}
delay(3000);
} else {
my_LED_strip.fill(0xff0000);
my_LED_strip.show();
delay(500);
my_LED_strip.fill(0x000000);
my_LED_strip.show();
delay(500);
}
}