Latest attempt below. The RTC has been set when deployed via rtc.adjust(DateTime(2020, 8, 12, 16, 32, 0));
in the setup & the serial monitor correctly returns the time. However, the two tactile buttons do not alter the time.
Once I have this sorted the next hurdle will be to alter which LED's fire based on the time.
Any comments/advise would be greatly receieved.
Thank you.
#include <Adafruit_NeoPixel.h>
#include <TimeLib.h>
#include "RTClib.h"
RTC_DS3231 rtc;
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 32
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// Declare integer array with size corresponding to number of Neopixels in chain
// int individualPixels[NUMPIXELS];
//Declare pins for decrementing/incrementing current time by 5 minutes
#define PLUSONEMIN 4
#define PLUSONEHOUR 5
// Current and previous states for button pins -- in setup initialize all to HIGH
int minusPrevState=HIGH;
int minusCurrState=HIGH;
int plusPrevState=HIGH;
int plusCurrState=HIGH;
// Time variables
int h;
int m;
int s;
// RGB color variables
int red=25;
int green=25;
int blue=25;
void setup()
{
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
rtc.adjust(DateTime(2020, 8, 12, 16, 32, 0));
}
pinMode(PLUSONEMIN, INPUT_PULLUP); //Define pin as input, enable pull-up resistor
pinMode(PLUSONEHOUR, INPUT_PULLUP); //Define pin as input, enable pull-up resistor
setTime(8,14,0,4,8,2020); //Initialize current time as Midnight/noon 08/31/2015
pixels.begin(); //Begin Neopixel string
Serial.begin(9600); //Begin Serial for debugging purposes
}
void loop()
{
DateTime now = rtc.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.println();
//Declare integer array with size corresponding to number of Neopixels in chain
int individualPixels[NUMPIXELS]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
/* Check for button presses & reset time if necessary */
minusCurrState=digitalRead(PLUSONEMIN); //Get current state of PLUSONEMIN button
/* If current state is different from previous state and value is now LOW, add one minute from current time */
if ((minusCurrState!=minusPrevState) && (minusCurrState==HIGH)){
adjustTime(1*60); //Shift time one minute forwards
minusPrevState=minusCurrState;
}
else{
minusPrevState=minusCurrState;
}
plusCurrState=digitalRead(PLUSONEHOUR); //Get current state of PLUSONEHOUR button
/* If current state is different from previous state and value is now LOW, add one hour from current time */
if ((plusCurrState!=plusPrevState) && (plusCurrState==HIGH)){
adjustTime(60*60); //Shift time on hour forward
plusPrevState=plusCurrState;
}
else{
plusPrevState=plusCurrState;
}
/* Get current time */
h=hourFormat12(); // Returns the hour of current time between 1-12
m=minute(); // Returns the minute of current time
s=second(); // Returns the second of current time (not used, included for completeness)
//Serial.print(h);
//Serial.print(":");
//Serial.print(m);
//Serial.print(":");
//Serial.println(s);
/* Parse time values to light corresponding pixels */
individualPixels[0]=1; //Light "IT"
individualPixels[1]=1; //Light "IS"
/* Minutes between 0-5 - Light "O CLOCK" */
if ((m>=0 && m<5)){
individualPixels[28]=1;
individualPixels[29]=1;
}
/* Minutes between 5-10 or 55-60 - Light "FIVE," "MINUTES" */
if ((m>=5 && m<10) || (m>=55 && m<60)){
individualPixels[8]=1;
individualPixels[9]=1;
individualPixels[10]=1;
}
/* Minutes between 10-15 or 50-55 - Light "TEN," "MINUTES" */
if ((m>=10 && m<15) || (m>=50 && m<55)){
individualPixels[2]=1;
individualPixels[9]=1;
individualPixels[10]=1;
}
/* Minutes between 15-20 or 45-50 - Light "QUARTER" */
if ((m>=15 && m<20) || (m>=45 && m<50)){
individualPixels[6]=1;
individualPixels[7]=1;
}
/* Minutes between 20-25 or 40-45 - Light "TWENTY," "MINUTES" */
if ((m>=20 && m<25) || (m>=40 && m<45)){
individualPixels[4]=1;
individualPixels[5]=1;
individualPixels[9]=1;
individualPixels[10]=1;
}
/* Minutes between 25-30 or 35-40 - Light "TWENTY," "FIVE," "MINUTES" */
if ((m>=25 && m<30) || (m>=35 && m<40)){
individualPixels[4]=1;
individualPixels[5]=1;
individualPixels[8]=1;
individualPixels[9]=1;
individualPixels[10]=1;
}
/* Minutes between 30-35 - Light "HALF" */
if ((m>=30 && m<35)){
individualPixels[3]=1;
}
/* Minutes between 5-35 - Light "PAST" */
if ((m>=5) && (m<35)){
individualPixels[14]=1;
}
/* Minutes between 35-60 - Light "TO" & MODIFY CURRENT HOUR VALUE */
if (m>=35){
individualPixels[13]=1;
h++; //Add 1 from current hour
/*Set time to twelve for hour around midnight, noon */
if (h==0){
h=12;
}
/*Corner case for 12:35-12:59 */
if (h==13){
h=1;
}
}
/* Hour=1 - Light "ONE" */
if (h==1){
individualPixels[12]=1;
}
/* Hour=2 - Light "TWO" */
if (h==2){
individualPixels[11]=1;
}
/* Hour=3 - Light "THREE" */
if (h==3){
individualPixels[15]=1;
individualPixels[16]=1;
}
/* Hour=4 - Light "FOUR" */
if (h==4){
individualPixels[17]=1;
}
/* Hour=5 - Light "FIVE" */
if (h==5){
individualPixels[18]=1;
}
/* Hour=6 - Light "SIX" */
if (h==6){
individualPixels[23]=1;
}
/* Hour=7 - Light "SEVEN" */
if (h==7){
individualPixels[21]=1;
individualPixels[22]=1;
}
/* Hour=8 - Light "EIGHT" */
if (h==8){
individualPixels[19]=1;
individualPixels[20]=1;
}
/* Hour=9 - Light "NINE" */
if (h==9){
individualPixels[24]=1;
}
/* Hour=10 - Light "TEN" */
if (h==10){
individualPixels[25]=1;
}
/* Hour=11 - Light "ELEVEN" */
if (h==11){
individualPixels[26]=1;
individualPixels[27]=1;
}
/* Hour=12 - Light "TWELVE" */
if (h==12){
individualPixels[30]=1;
individualPixels[31]=1;
}
/* Light pixels corresponding to current time */
for (int i=0; i<sizeof(individualPixels); i++){
if (individualPixels[i]==1){
pixels.setPixelColor(i, pixels.Color(red,green,blue)); //Set Neopixel color
}
else{
pixels.setPixelColor(i,pixels.Color(0,0,0));
}
}
pixels.show(); //Display Neopixel color
// /* Clear pixel values for re-assignment during next iteration */
// for (int j=0; j<sizeof(individualPixels); j++){
// individualPixels[j]=0; //Set array values to 0
// pixels.setPixelColor(j, pixels.Color(0,0,0)); //Set Neopixel color to 0 brightness, i.e. off
// }
}