Muchas gracias por la contestación Kike_GL. Ya tengo en cuenta la memoria que utilizo y aunque tengo que trabajar con la clase String creo que el NANO me da suficiente y siempre tengo de desbrozar el código para ahorrar memoria y en último caso utilizar un MEGA aunque el espacio en el hardware del proyecto también es importante.
Claro que utilizo funciones de usuario e intento seguir las reglas de encapsulación aunque mi experiencia viene de programar en lenguaje procedural intento entender y aplicar los principios de la POO.
Soy autodidacta lo que me pone a veces frente a un muro con algún problema básico como el de dividir el código.
Lo que necesito es orientación para encontrar bibliografía en castellano preferentemente o en inglés. Muchas gracias, adjunto el código, lo que pretendo es dividir el código en módulos por cada función, hasta ahora he incluido solo el reloj, pero me faltan un par más.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#define pinBAND 0
#define pinREVERSE 1
#define pinFORWARD 2
#define pinBANDS 6
#define pinPOWER 7
#define pinANTENNA_AEF 8
#define pinANTENNA_HEX 7
unsigned long timeFOR_ACTION = 0;
int initialDAY;
enum Antenna {antennaHEX = 0, antennaAEF = 1};
enum Bands {b6 = 1, b10 = 2, b15 = 3, b20 = 4, b30 = 5, b40 = 6, b80 = 7, b160 = 8};
LiquidCrystal_I2C lcd(0x3f, 20, 4);
RTC_DS3231 rtc;
/* RELOJ
*/
String nameOfMonth (int m) {
switch (m) {
case 1: return "ENE";
case 2: return "FEB";
case 3: return "MAR";
case 4: return "ABR";
case 5: return "MAY";
case 6: return "JUN";
case 7: return "JUL";
case 8: return "AGO";
case 9: return "SEP";
case 10: return "OCT";
case 11: return "NOV";
case 12: return "DIC";
}
}
String nameOfTheDayOfTheWeek (int d) {
switch (d) {
case 0: return "DOMINGO";
case 1: return "LUNES";
case 2: return "MARtES";
case 3: return "MIERCOLES";
case 4: return "JUEVES";
case 5: return "VIERNES";
case 6: return "SABADO";
}
}
int calcUtcOffset (DateTime t) {
if ((t.month() > 3 || (t.month() == 3 && t.day() >= 25)) &&
(t.month() < 10 || (t.month() == 10 && t.day() <= 25))) {
return -2;
} else {
return -1;
}
}
void setTimeClock () {
int initYear = 2019;
int initMonth = 10;
int initDay = 3;
int initHour = 18;
int initMinute = 20;
rtc.adjust(DateTime(initYear, initMonth, initDay, initHour, initMinute, 0));
}
void showDate (DateTime t) {
String t_date = String(t.day());
t_date.concat(" ");
t_date.concat(nameOfMonth(t.month()));
t_date.concat(" * " );
t_date.concat(nameOfTheDayOfTheWeek(t.dayOfTheWeek()));
int colPosition = int((20 - t_date.length()) / 2);
lcd.setCursor(colPosition, 0);
lcd.print(t_date);
}
void showTime (DateTime t) {
int utcOffset = calcUtcOffset(t);
char buf_time_local[9];
snprintf(buf_time_local, sizeof(buf_time_local), "%02d:%02d:%02d",
t.hour(), t.minute(), t.second());
char buf_time_utc[6];
snprintf(buf_time_utc, sizeof(buf_time_utc), "%02d:%02d",
t.hour() + utcOffset, t.minute());
lcd.setCursor(0, 1);
lcd.print(buf_time_local);
lcd.print(" ");
lcd.print(buf_time_utc);
lcd.print(" (UTC)");
}
//setTimeClock();
/* CONTROL DE ANTENAS
*/
void setup() {
Serial.begin(9600);
Serial.flush();
lcd.init();
lcd.backlight();
lcd.clear();
rtc.begin();
DateTime nowTime = rtc.now();
initialDAY = nowTime.day();
showDate(nowTime);
showTime(nowTime);
}
void loop() {
int delaySeconds = 1;
if (millis() > timeFOR_ACTION) {
timeFOR_ACTION = millis() + delaySeconds;
DateTime nowTime = rtc.now();
if (nowTime.day() != initialDAY) {
showDate(nowTime);
}
showTime(nowTime);
int rawPower = analogRead(pinPOWER);
if (rawPower > 100) {
int rawBand = analogRead(pinBAND);
}
}
}