Hello
im working on a word clock project, iam a novice in world of coding so i have been googling around a actually got a word clock code to work, with some pieces here and there.
but i have learned that my clock is not accurate, it keep loosing a few ms over time and in a month some minutes, so i*am trying to add a RTC module like DS3231.
but i dont know how or where i should add it.
cant really find any tutorials on how to use the hh and mm and sec from DS3231 to control my led strip or normal leds.
anyone?
PART 1
#include <Time.h>
#include <TimeLib.h>
/*
Arduino + Neopixel Word Clock Code
by: Alex - Super Make Something
date: August 16, 2015
license: Public domain. Please use, reuse, and modify this sketch!
additional: modified from "simple.ino" NeoPixel example sketch by Shae Erisson of Adafruit Industries.
NOTE: REQUIRES NEOPIXEL & TIME LIBRARIES TO BE INSTALLED UNDER ...\Arduino\libraries
NEOPIXEL LIBRARY AVAILABLE AT: https://github.com/adafruit/Adafruit_NeoPixel
TIME LIBRARY AVAILABLE AT: https://github.com/PaulStoffregen/Time
Explanation: This code lights up Neopixels corresponding to the current time.
Time is kept using the time library.
Neopixels are lit using the Adafruit Neopixel library.
Depending on the current time, flags to light corresponding Neopixels are saved in an array
After parsing the time, Neopixels are turned on/off according to the flags using a for loop
*/
/*
Dette er version 1.0
har 2 knapper som �ker � minsker tiden med 5min.
3x pot meter som forandrer fargene individuelt med � �ke / minske RGB komponentene.
photo sensor som automatisk �ker eller minsker brightness
m� nok justere den b�de i code i motstanden s� den wirke bedre.
er ikke brukt chrono dot elr s�nn time keeping chip.
arduino uno.
*/
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#include "Time.h"
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 3
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 32
#define LIGHT_SENSOR_PIN A4
#define RED_POT_PIN A5
#define GREEN_POT_PIN A2
#define BLUE_POT_PIN A3
// 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 MINUSFIVEMINS 4
#define PLUSFIVEMINS 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=0;
int green=0;
int blue=0;
void setup()
{
pinMode(MINUSFIVEMINS, INPUT_PULLUP); //Define pin as input, enable pull-up resistor
pinMode(PLUSFIVEMINS, INPUT_PULLUP); //Define pin as input, enable pull-up resistor
setTime(12,0,0,31,8,2015); //Initialize current time as Midnight/noon 08/31/2015
pixels.begin(); //Begin Neopixel string
Serial.begin(9600); //Begin Serial for debugging purposes
pinMode(RED_POT_PIN , INPUT);
pinMode(GREEN_POT_PIN , INPUT);
pinMode(BLUE_POT_PIN , INPUT);
}
void loop()
{
//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(MINUSFIVEMINS); //Get current state of MINUSFIVEMINS button
/* If current state is different from previous state and value is now LOW, subtract five minutes from current time */
if ((minusCurrState!=minusPrevState) && (minusCurrState==LOW)){
adjustTime(-5*60); //Shift time five minutes backwards
minusPrevState=minusCurrState;
}
else{
minusPrevState=minusCurrState;
}
plusCurrState=digitalRead(PLUSFIVEMINS); //Get current state of PLUSFIVEMINS button
/* If current state is different from previous state and value is now LOW, add five minutes from current time */
if ((plusCurrState!=plusPrevState) && (plusCurrState==LOW)){
adjustTime(5*60); //Shift time five minutes forwards
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);