Hi, request for help. Can you please tell me what I'm doing wrong?
So I've got code that displays time on a led 16x8 LED matrix. It works fine (see code below).
What I'm trying to do is every 30 min have a set of eyeballs come on the led screen matrix (for 15 seconds let say), and then after the 15 seconds the time comes back up and runs until the next 30 min mark.
The eyeball code works fine separately on its own (see next comment).
I tried putting the eyeball code in a separate subroutine (called "eyeballs") and used a conditional statement to execute it, but it doesn't work. It seems my conditional statement is ignored.
Here's the conditional statement I tried.
void loop () {
DateTime now = rtc.now();
if(now.hour() == 23 && now.minutes() == 30){
eyeballs();
Is there something wrong with it? Will a conditional statement run a subroutine? It's reading the time correctly (e.g. instead of eyeballs, I did Serial.print "test" and it ran for a full min. But it's not executing the subroutine (or function I think is the proper term).
Here's the clock code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int previousMinute = -1;
bool DEBUG = false;
Adafruit_8x16minimatrix matrix = Adafruit_8x16minimatrix();
//3x9 number digit font bitmaps
byte one[]= {B01000000,
B11000000,
B01000000,
B01000000,
B01000000,
B01000000,
B01000000,
B11100000};
byte two[]= {B11100000,
B00100000,
B00100000,
B11100000,
B10000000,
B10000000,
B10000000,
B11100000};
byte three[]= {B11100000,
B00100000,
B00100000,
B11100000,
B00100000,
B00100000,
B00100000,
B11100000};
byte four[]= {B10100000,
B10100000,
B10100000,
B11100000,
B00100000,
B00100000,
B00100000,
B00100000};
byte five[]= {B11100000,
B10000000,
B10000000,
B11100000,
B00100000,
B00100000,
B00100000,
B11100000};
byte six[]= {B11100000,
B10000000,
B10000000,
B11100000,
B10100000,
B10100000,
B10100000,
B11100000};
byte seven[]={B11100000,
B00100000,
B00100000,
B00100000,
B00100000,
B00100000,
B00100000,
B00100000};
byte eight[]={B11100000,
B10100000,
B10100000,
B11100000,
B10100000,
B10100000,
B10100000,
B10100000,
B10100000,
B11100000,
B00100000,
B00100000,
B00100000,
B00100000};
byte nine []={ B11100000,
B10100000,
B11100000,
B00100000,
B0100000,
B00100000,
B00100000,
B11100000};
byte zero[]={ B11100000,
B10100000,
B10100000,
B10100000,
B10100000,
B10100000,
B10100000,
B11100000};
char *noArray[] = {zero, one, two, three, four, five, six, seven, eight, nine};
void setup() {
Serial.begin(9600);
matrix.begin(0x70); // pass in the address
matrix.setRotation(1);
}
String convertIntTo2DigitString(int i) {
String s = String(i);
if (i < 10) {
s = '0'+s;
}
return s;
}
void loop(){
matrix.setBrightness(1);
DateTime now = rtc.now();
int currentMinute = now.minute();
int currentHour = now.hour();
int currentSecond = now.second();
if (DEBUG) {
currentHour = currentMinute;
currentMinute = now.second();
}
if (previousMinute != currentMinute) {
previousMinute = currentMinute;
String min = convertIntTo2DigitString(currentMinute);
String hour = convertIntTo2DigitString(currentHour);
matrix.clear();
matrix.drawBitmap(0, 0, (byte*)noArray[(int)hour[0]-'0'], 3, 9, LED_ON);
matrix.drawBitmap(4, 0, (byte*)noArray[(int)hour[1]-'0'], 3, 9, LED_ON);
matrix.drawBitmap(9, 0, (byte*)noArray[(int)min[0]-'0'], 3, 9, LED_ON);
matrix.drawBitmap(13,0, (byte*)noArray[(int)min[1]-'0'], 3, 9, LED_ON);
matrix.writeDisplay();
delay(200);
}
}