I have searched for this but only found information about the difference between Setup and Void Loop, which I understand.
So with the code I am working on, where I have added LED PWM to a RTC Clock code.
The code works, but the PWM timings are affected by the RTC Delay
So, a couple of questions, what is the two "Void" after the Void Loop and is there a way to segregate the two parts of the code, so that the PWM does not effect the RTC or vice versa?
#include <TM1637.h>
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#define CLK 9
#define DIO 8
int ledPin = 6;
TM1637 Display1(CLK, DIO);
int8_t Digitos[] = {0,1,2,3};
int horas;
int minutos;
boolean alterna;
void setup() {
Serial.begin(9600);
while (!Serial) ; // wait for serial
delay(200);
Serial.println("DS1307RTC Read Test");
Serial.println("-------------------");
Display1.set();
Display1.init();
}
void loop() {
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 100; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for (int fadeValue = 100 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
tmElements_t tm;
if (RTC.read(tm)) {
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
horas = tm.Hour;
minutos = tm.Minute;
CalculaDigitos(horas, minutos);
if (alterna)
{
Display1.point(POINT_OFF);
alterna = false;
}
else
{
Display1.point(POINT_ON);
alterna = true;
}
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(1000);
}
void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
}
void CalculaDigitos( int hor, int minu)
{
int8_t Digit0 = minu %10 ;
int8_t Digit1 = (minu % 100) / 10 ;
int8_t Digit2 = hor % 10 ;
int8_t Digit3 = (hor % 100) / 10 ;
Digitos[3] = Digit0 ;
Digitos[2] = Digit1 ;
Digitos[1] = Digit2 ;
Digitos[0] = Digit3 ;
Display1.display(Digitos);
}