Hi there,
I'm working in an arduino based wordclock.
I worked a lot on the code. I set the correct time in the RTC DS1307 module.
Yet as a coding newbie I need your help !
#include "Wire.h"
#define DS1307_ADDRESS 0x68
#include <Adafruit_NeoPixel.h>
#define RGBLEDPIN 6
#define N_LEDS 114 // 11 x 10 grid + 4 aux coins
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(N_LEDS, RGBLEDPIN, NEO_GRB + NEO_KHZ800);
uint32_t WHITE = pixels.Color(255, 255, 255); // Défini la couleur
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// WORDS
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void LEDSOFF() {
for(int i=0;i<N_LEDS;i++){
pixels.setPixelColor(i, pixels.Color(0,0,0));
pixels.show();
}
}
void showILEST() // = IT IS
{
pixels.setPixelColor(1, WHITE);
pixels.setPixelColor(2, WHITE);
pixels.setPixelColor(4, WHITE);
pixels.setPixelColor(5, WHITE);
pixels.setPixelColor(6, WHITE);
}
void showVINGT() // =TWENTY
{
pixels.setPixelColor(90, WHITE);
pixels.setPixelColor(91, WHITE);
pixels.setPixelColor(92, WHITE);
pixels.setPixelColor(93, WHITE);
pixels.setPixelColor(94, WHITE);
}
void showVINGTCINQ()
{
showVINGT();
pixels.setPixelColor(95, WHITE);
pixels.setPixelColor(96, WHITE);
pixels.setPixelColor(97, WHITE);
pixels.setPixelColor(98, WHITE);
pixels.setPixelColor(99, WHITE);
}
// I Removed a lot of functions to fit in the post but you have the idea
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Appel de l'heure enregistrée sur la DS1307 / Call Hours and minutes from DS1307
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
}
void isPast()
{ boolean (minute > 30 = true)
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Light leds regarding hours and minutes
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void AfficheLeds() {
LEDSOFF();
{
showILEST();
if(minute < 5 and hour == 1 ) {
showHEURE();
} else if(minute < 5 and (hour != 12 || hour != 0 || hour != 1) ){
showHEURES
} if(minute == 1) {
showPLUSUN();
} else if(minute == 2) {
showPLUSDEUX();
} else if(minute == 3) {
showPLUSTROIS();
} else if(minute == 4) {
showPLUSQUATRE();
} else if(minute == 5) {
showCINQ();
} else if(minute == 6) {
showPLUSUN();
showCINQ();
same idea till 29
} else if(minute == 30 and (hour != 12 || hour != 0 )) {
showETDEMIE();
} else {
showETDEMI();
same idea till 59
} else if(minute == 59) {
showMOINS();
showPLUSUN();
}
if(hour == 0) {
if(isPast) {
showMINUIT();
} else {
showUNE();
}
} else if(hour == 12) {
if(isPast) {
showMIDI();
} else {
showUNE();
}
} else if(hour == 1 || hour == 13) {
if(isPast) {
showUNE();
} else {
showDEUX();
}
} else if(hour == 2 || hour == 14) {
if(isPast) {
showDEUX();
} else {
showTROIS();
}
} IDEM JUSQU'A MINUIT
else if(hour == 23) {
if(isPast) {
showONZE();
} else {
showMINUIT();
}
}
}
pixels.show(); // cela actualise l'affichage des leds Leds LightON
}
void setup(){
Wire.begin();
pixels.begin();
}
void loop(){
printDate();
delay(1000);
AfficheLeds();
}
The main issue I'm facing is that some functions are not recognised
I was thinking that I could reuse "minute" et "hour" as I defined them with "int"
I have the correct time in the serial.
error: 'minute' was not declared in this scope
error: 'hour' was not declared in this scope
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
The second point is : I cant define a function who is telling that minutes are > 30. If this function "is Past" I will reuse it in the time to words definition (eg I can write 20 to 10 even if hours in the serials are 9)
void isPast()
{ boolean (minute > 30 ; true)
}
As "minute" is not defined I can't work on the function structure. I know it's incorrect...
The "if else" part is not correct but I'll see later to fix it.
Thanks for your help
Louison