#include <Servo.h>
#include <FastLED.h>
#include "time.h"
#include <DS1307RTC.h>
#define ring_num_leds 16
const int led1_num_leds =1;
const int led1Pin =11;
const int led2_num_leds =1;
const int led2Pin =10;
const int led3_num_leds =1;
const int led3Pin =9;
// blink patterns
const long blink1OnDuration = 1000;// ON time for LED in blink pattern 1
const long blink1OffDuration = 1000;// OFF time for LED in blink pattern 1
const long blink2OnDuration = 200;// ON time for LED in blink pattern 1
const long blink2OffDuration = 200;// OFF time for LED in blink pattern 1
int led1State = HIGH;// initial state of Led1; Is this LED on or off;
int led2State = HIGH;// initial state of Led2; Is this LED on or off;
int led3State = HIGH;// initial state of Led3; Is this LED on or off;
long rememberTimeForBlink1=0;// setting up a spot to store the current time
long rememberTimeForBlink2=0;// setting up a spot to store the current time
CRGB ring_leds[ring_num_leds];
CRGB led1[led1_num_leds];
CRGB led2[led2_num_leds];
CRGB led3[led3_num_leds];
int t = now(); // Store the current time in time
String dayOfWeek = weekday(t); // Day of the week for the given
Servo servo1; // Creates servo object
Servo servo2; // Creates servo object
int pos = 0;
void setup() {
pinMode(led1Pin,OUTPUT); // Sets this pin to OUTPUT the board's voltage
digitalWrite(led1Pin,led1State); // Ditto above
FastLED.addLeds<NEOPIXEL, 12>(ring_leds, 16);
FastLED.addLeds<NEOPIXEL, 11>(led1, 1);
FastLED.addLeds<NEOPIXEL, 10>(led2, 1);
FastLED.addLeds<NEOPIXEL, 9>(led3, 1);
Serial.begin(115200); // Setting up th console to show
// servos
servo1.attach(3); // Servo1 is attached to this pin
servo2.attach(4); // Servo2 is attached to this pin
servo1.write(0); // Servo1 initial starting position
servo2.write(0); // Servo2 initial starting position
delay(1000); // Pause to let servos reach the correct starting position
} // ending setup
int blink1(){
if( led1State == HIGH )
{
if( (millis()- rememberTimeForBlink1) >= blink1OnDuration){
led1[0]=CRGB::Red;// change the state of LED
led1State=LOW;
rememberTimeForBlink1=millis();// remember Current millis() time
}
}
else
{
if( (millis()- rememberTimeForBlink1) >= blink1OffDuration){
led1[0]=CRGB::Black;// change the state of LED
led1State=HIGH;
rememberTimeForBlink1=millis();// remember Current millis() time
}
}
}
int blink2(){
if( led2State == HIGH )
{
if( (millis()- rememberTimeForBlink2) >= blink2OnDuration){
led2[0]=CRGB::Blue;// change the state of LED
led2State=LOW;
rememberTimeForBlink2=millis();// remember Current millis() time
}
}
else
{
if( (millis()- rememberTimeForBlink2) >= blink2OffDuration){
led2[0]=CRGB::Black;// change the state of LED
led2State=HIGH;
rememberTimeForBlink2=millis();// remember Current millis() time
}
}
}
void loop() {
// test servos
for (pos = 45; pos <= 55; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo1.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos+90);
}
for (pos = 45; pos >= 55; pos -= 1) { // goes from 180 degrees to 0 degrees
servo1.write(pos); // tell servo to go to position in variable 'pos'
servo2.write(pos+90);
}
// test ring lights
fill_solid(ring_leds,ring_num_leds,CRGB::Green);
FastLED.show();
// test individual leds w/ blinks
blink1();
blink2();
// for clock
Serial.print("Time: ");
Serial.println(dayOfWeek);
// Serial.print("led1State: ");
// Serial.println(led1State);
// Serial.print("rememberTime: ");
// Serial.println(led1State);
// Serial.println(rememberTime);
// Serial.print("millis: ");
// Serial.println(millis(),6);
// Serial.print("\n");
}// void loop ends