#include <Adafruit_NeoPixel.h>
#define NEOPIXEL_PIN 7
#define PIXEL_COUNT 144
//structure to keep time variables together
typedef struct {
byte hour;
byte minute;
byte second;
}clockTime;
clockTime analogClock = {1, 59, 55}; //creates analog clock struct
//Initialises the NEOPIXEL with its object
Adafruit_NeoPixel pixels(PIXEL_COUNT, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
void incrementTime()
{
analogClock.second++; //increment clock by 1 second
//check if second is above 59
if(analogClock.second > 59)
{
analogClock.second = 0;
analogClock.minute++;
}
//check if minute is above 59
if(analogClock.minute > 59)
{
analogClock.minute = 0;
analogClock.hour++;
}
//check if hour is above 24
if(analogClock.hour > 23) analogClock.hour = 0;
}
void setNeoPixel()
{
int hourPixel = (analogClock.hour);
int minutePixel = (analogClock.minute) + 24; //offset by 24 due to hour
int secondPixel = (analogClock.second) + 84; //offset by (24 + 60) due to hour and minute
pixels.clear();
pixels.setPixelColor(hourPixel, pixels.Color(0, 255, 0));
pixels.setPixelColor(minutePixel, pixels.Color(0, 255, 0));
pixels.setPixelColor(secondPixel, pixels.Color(0, 255, 0));
pixels.show();
}
void setup()
{
//Initialises neopixel
pixels.begin();
}
void loop()
{
setNeoPixel(); //Set pixel display
delay(1000);
incrementTime(); //Increments the time variables
}