I have had this problem a few times, it seems the Arduino IDE and the serial monitor is incredibly unstable, unless it's user error but judging from the fact that I hadn't even touched anything before it broke, I would say it's not me.
It was working the night before but this morning it just wouldn't print anything to the serial monitor from my code, however if I start one of the communication example codes like the ASCII example, it prints fine...I'm using the arduino uno, but I have a couple of dues too, so I tried the script on the due and it printed fine to the serial monitor.
Here is my code, could someone check my code and see if they can print to the serial monitor or not?
/*
Pins:
RTC:
5V to VCC
GND to GDN
A4 to SDA
A5 to SLC
*/
#include <Wire.h>
#include "RTClib.h"
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
//Words //0 //1 //2 //3 //4 //5 //6 //7 //8 //9 //10 //11 //12 //13 //14 //15 //16 //17 //18 //19 //20 //21 //22 //23 //24 //25//26 //27
char* w[] = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty", "Thirty", "Forty", "Fifty", "Keeg Jo And Mat 2016", "", " ", "Good",
//28 //29 //30 //31 //32 //33 //34 //35 //36 //37 //38
"Morning", "Afternoon", "Evening", "It Is", "Past", "To", "Quarter", "Half", "O'Clock", "AM", "PM"
};
//End Words
int timeType = 0;
int _hour = 0;
int dayInput = 0;
int hourInput = 0;
int minuteInput = 0;
int iDay = 0;
int iHour = 0;
int iMinute = 0;
void setup () {
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
Serial.begin(57600);
pinMode(11, INPUT);//Minutes
pinMode(12, INPUT);//Hours
pinMode(13, INPUT);//Day
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
//rtc.adjust(DateTime(2016, 3, 11, 10, 51, 0));
}
//rtc.adjust(DateTime(2016, 3, 11, 1, 0, 50));
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop () {
DateTime now = rtc.now();
minuteInput = digitalRead(11);
hourInput = digitalRead(12);
dayInput = digitalRead(13);
if (minuteInput == HIGH) {
Serial.println("Minute");
} else if (hourInput == HIGH) {
Serial.println("Hour");
} else if (dayInput == HIGH) {
Serial.println("Day");
}
Line();
if (now.minute() == 0) {
timeType = 0;
} else if (now.minute() > 0 && now.minute() <= 20) {
timeType = 1;
} else if (now.minute() > 20 && now.minute() < 50 && now.minute() != 30 && now.minute() != 45) {
timeType = 0;
} else if (now.minute() >= 50 && now.minute() < 60) {
timeType = 2;
} else if (now.minute() == 30) {
timeType = 3;
} else if (now.minute() == 45) {
timeType = 4;
}
ps("Time Type: ");
pi(timeType);
Line();
Line();
//Greeting
p(27);
Space();
if (now.hour() >= 0 && now.hour() < 12) {
p(28);
} else if (now.hour() >= 12 && now.hour() < 18) {
p(29);
} else if (now.hour() >= 18 && now.hour() < 24) {
p(30);
}
Line();
Line();
//Time (It Is) Time Type 0
if (timeType == 0) {
Itis();
hours(0);
Space();
_minutes();
OClock();
}
//Time (Past) Time Type 1
if (timeType == 1) {
Itis();
_minutes();
Past();
hours(0);
OClock();
}
//Time (To) Time Type 2
if (timeType == 2) {
Itis();
_minutes();
To();
hours(0);
OClock();
}
//Time (Half Past) Time Type 3
if (timeType == 3) {
Itis();
p(35);
Past();
hours(0);
}
//Time (Quarter To) Time Type 4
if (timeType == 4) {
Itis();
p(34);
To();
hours(1);
}
//AM/PM
AMPM();
Line();
Line();
//Day
//Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
ps(daysOfTheWeek[now.dayOfTheWeek()]);
Line();
Line();
pl(24);
Serial.println("--------------------------------------------------");
Serial.println("--------------------------------------------------");
delay(1000);
}
//------------------------------------------------
void Line() {
pl(25);
}
void Itis() {
p(31);
Space();
}
void Past() {
Space();
p(32);
Space();
}
void To() {
Space();
p(33);
Space();
}
void Space() {
p(26);
}
void OClock() {
DateTime now = rtc.now();
if (now.minute() == 0 || now.minute() == 60) {
Space();
p(36);
}
}
void AMPM() {
Space();
DateTime now = rtc.now();
bool am = false;
if (now.hour() > 12) {
am = false;
} else {
am = true;
}
if (am) {
p(37);
} else {
p(38);
}
}
void p(int i) {
Serial.print(w[i]);
}
void pl(int i) {
Serial.println(w[i]);
}
void ps(char* i) {
Serial.print(i);
}
void pi(int i) {
Serial.print(i);
}
void _minutes() {
DateTime now = rtc.now();
int minutes = 0;
if (timeType == 2) {
minutes = 60 - now.minute();
} else {
minutes = now.minute();
}
int i = minutes;
if (i <= 20 && i != 0) {
p(i);
} else if (i > 20 && i < 30) {
p(20);
Space();
p(i - 20);
} else if (i > 30 && i < 40) {
p(21);
Space();
p(i - 30);
} else if (i > 40 && i < 50 && i != 45) {
p(22);
Space();
p(i - 40);
} else if (i > 50 && i < 60) {
p(23);
Space();
p(i - 50);
} else if (i == 30) {
p(35);
} else if (i == 40) {
p(22);
} else if (i == 50) {
p(23);
}
}
void hours(int m) {
DateTime now = rtc.now();
if (now.hour() > 12) {
_hour = now.hour() - 12;
} else {
_hour = now.hour();
}
_hour = _hour + m;
p(_hour);
}