Il codice.
Ovviamente serviranno le librerie che si vedono incluse all'inizio.
Sulla RTClib mi sembra di aver dovuto fare qualche modifica, mentre sulla phi_prompt ho sicuramento tradotto YES e NO in SI e NO e modificato il valore alla riga 419 del file phi_interfaces.cpp da 10 ad 80, ma non è detto che serva...)
Occorrerà reimpostare i valori dei pulsanti analogici rispetto a quelli rilevati dal proprio dispositivo, i miei sono 70,220,460,625,950
Poi c'è la parte per rilevare la temperatura, che comprende le librerie OneWire e DallasTemperature quindi da non includere per chi non usa il sensore di temperatura così come tutte le parti di codice interessate.
Ho qualche dubbio su come ho gestito il debug su monitor seriale, non ho capito se fosse meglio chiudere il codice in degli #ifdef...
Questo è il mio primo progetto con Arduino e mi piacerebbe ricevere suggerimenti da qualcuno più esperto su come potrei migliorare il mio codice! 
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal.h>
#include <stdio.h>
#include <avr/pgmspace.h>
#include <phi_interfaces.h>
#include <phi_prompt.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <EEPROM.h>
#include <EEPROMVar.h>
//Phi-2 shield LCD pin setting
#define LCD_RS 8
#define LCD_EN 9
#define LCD_D4 4
#define LCD_D5 5
#define LCD_D6 6
#define LCD_D7 7
#define SS 15 //Sector size
#define lcd_rows 2
#define lcd_columns 16
#define analog_buttons_per_column 5 // Each analog pin has five buttons with resistors.
#define analog_buttons_per_row 1 // There are two analog pins in use.
const bool DEBUG = false;
RTC_DS1307 RTC;
OneWire ourWire(2);//2 = pin temperatura
DallasTemperature tempSensor(&ourWire);
const int ledPinBlue = 3; // select the pin for the LED
const int ledPinWhite = 11;
/******************************************************************/
// PHI LIBRARY
/*****************************************************************/
// This is an analog keypad.
char analog_mapping[] = {
'R','U','D','L','B'};
byte analog_pins[] = {
0}; // The pin numbers are analog pin numbers.
int values[]={
70,220,460,625,900};//(70,220,460,625,950_OK)
phi_analog_keypads analog_keypad(analog_mapping, analog_pins, values, analog_buttons_per_row, analog_buttons_per_column);
// This serial keypad is for debugging.
phi_serial_keypads debug_keypad(&Serial,57600);
// The following sets up function keys for phi_prompt library
char up_keys[]={
"U"};
char down_keys[]={
"D"};
char left_keys[]={
"L"};
char right_keys[]={
"R"};
char enter_keys[]={
"B"};
char escape_keys[]={
"A"};
char * function_keys[]={
up_keys,down_keys,left_keys,right_keys,enter_keys,escape_keys};
// The following adds all available keypads as inputs for phi_prompt library
multiple_button_input * keypads[]={
&analog_keypad, &debug_keypad,0};
LiquidCrystal lcd(LCD_RS,LCD_EN,LCD_D4,LCD_D5,LCD_D6,LCD_D7); // Create the lcd object
/**************************************************************************/
// KRUSDUINO
/**************************************************************************/
byte bled[96] = {
1, 1, 1, 1, 1, 1, 1, 1, //0 - 1
1, 1, 1, 1, 1, 1, 1, 1, //2 - 3
1, 1, 1, 1, 1, 1, 1, 1, //4 - 5
1, 1, 1, 1, 7, 12, 15, 16, //6 - 7
18, 19, 20, 21, 22, 23, 24, 25, //8 - 9
26, 27, 28, 29, 30, 31, 32, 33, //10 - 11
34, 35, 34, 33, 32, 31, 30, 29, //12 - 13
28, 27, 26, 25, 24, 23, 22, 21, //14 - 15
20, 19, 18, 16, 15, 12, 7, 1, //16 - 17
1, 1, 1, 1, 1, 1, 1, 1, //18 - 19
1, 1, 1, 1, 1, 1, 1, 1, //20 - 22
1, 1, 1, 1, 1, 1, 1, 1 //22 - 23
};
byte wled[96] = {
0, 0, 0, 0, 0, 0, 0, 0, //0 - 1
0, 0, 0, 0, 0, 0, 0, 0, //2 - 3
0, 0, 0, 0, 0, 0, 0, 0, //4 - 5
0, 0, 0, 1, 4, 9, 14, 18, //6 - 7
64, 75, 87, 99, 113, 124, 135, 146, //8 - 9
157, 168, 177, 184, 190, 194, 198, 200, //10 - 11
202, 203, 202, 200, 198, 194, 190, 184, //12 - 13
177, 168, 157, 146, 135, 124, 113, 99, //14 - 15
87, 75, 64, 18, 14, 9, 4, 1, //16 - 17
0, 0, 0, 0, 0, 0, 0, 0, //18 - 19
0, 0, 0, 0, 0, 0, 0, 0, //20 - 22
0, 0, 0, 0, 0, 0, 0, 0 //22 - 23
}; //White LED array in RAM
const int bkl_pin = 10;
const byte bkl_IdleVal = 2; //3 PWM value for backlight at idle
byte second, minute, hour, day, month;//, year;
int year;
long previousMillisFive = 5000;//al primo giro scatta subito la funzione
int min_cnt ;
byte bled_out;
byte wled_out;
EEPROMVar<boolean> temp_bool = true;
EEPROMVar<byte> wled_out_man = 0;
EEPROMVar<byte> bled_out_man = 0;
//**************************
//LED Levels output KRUSDUINO
//*************************
void LED_levels_output(){
int sector, sstep, t1, t2;
if (min_cnt>=1440) {
min_cnt=1;
} // 24 hours of minutes
sector = min_cnt/SS; // divided by gives sector -- 15 minute
sstep = min_cnt%SS; // remainder gives add on to sector value
t1 =sector;
if (t1==95) {
t2=0;
}
else {
t2 = t1+1;
}
if (DEBUG) {
Serial.print(t1);
Serial.print("__");
Serial.print(sstep);
}
if (sstep==0)
{
bled_out = bled[t1];
wled_out = wled[t1];
}
else {
bled_out = check(&bled[t1], &bled[t2], sstep);
wled_out = check(&wled[t1], &wled[t2], sstep);
}
if(temp_bool){
analogWrite(ledPinBlue, bled_out);
analogWrite(ledPinWhite, wled_out);
}
else{
analogWrite(ledPinBlue, bled_out_man);
analogWrite(ledPinWhite, wled_out_man);
}
if (DEBUG) {
Serial.print(" >W ");
Serial.print(int(wled_out));
Serial.print(" -B ");
Serial.print(int(bled_out));
Serial.print(" .. ");
Serial.println(min_cnt);
}
}
byte check( byte *pt1, byte *pt2, int lstep){
byte result;
float fresult;
if (*pt1==*pt2) {
result = *pt1;
} // No change
else if (*pt1<*pt2) //Increasing brightness
{
fresult = ((float(*pt2-*pt1)/15.0) * float(lstep))+float(*pt1);
result = byte(fresult);
}
//Decreasing brightness
else {
fresult = -((float(*pt1-*pt2)/15.0) * float(lstep))+float(*pt1);
result = byte(fresult);
}
return result;
}
/****TEMP_PRINT**************/
void tempPrint(){
lcd.setCursor(10, 0);
lcd.print(tempSensor.getTempCByIndex(0));
lcd.print((char)223);
}
/*****LIGHT_POWER_PRINT*****/
void lightPrint(){
lcd.setCursor(0,1);
lcd.print(" ");//pulisce riga
lcd.setCursor(0,1);
lcd.print("Bianco");
temp_bool ? lcd.print(int(wled_out)) : lcd.print(int(wled_out_man));
lcd.print(" Blu");
temp_bool ? lcd.print(int(bled_out)) : lcd.print(int(bled_out_man));
if(!temp_bool){
lcd.setCursor(6,0);
lcd.print("MAN");
}
}
// format hours, mins into a readable time (24 hr format)
void printHM (byte hr, byte mn){
if(hr<10)lcd.print("0");
lcd.print(hr, DEC);
lcd.print(":");
if(mn<10)lcd.print("0");
lcd.print(mn, DEC);
}
void printDMYHM(byte dd, byte mon, int yr, byte hr, byte mn){
if(dd<10)lcd.print("0");
lcd.print(dd, DEC);
lcd.print("/");
if(mon<10) lcd.print("0");
lcd.print(mon, DEC);
lcd.print("/");
lcd.print(yr, DEC);
lcd.print(" ");
if(hr<10)lcd.print("0");
lcd.print(hr, DEC);
lcd.print(":");
if(mn<10)lcd.print("0");
lcd.print(mn, DEC);
}
void setDate(int y,byte mon, byte d, byte h,byte m) {
RTC.adjust(DateTime(y, mon, d, h, m, 0));//è giusto impostare al secondo 0
}
void getDate(byte *second,byte *minute,byte *hour,byte *day,byte *month,int *year) {
DateTime now = RTC.now();
*second = now.second();
*minute = now.minute();
*hour = now.hour();
*day = now.day();
*month = now.month();
*year = now.year();
}
/******************************************/
// START of SETUP
/******************************************/
void setup() {
if (DEBUG) Serial.begin(57600);
Wire.begin();//serve per l'RTC
RTC.begin();
/*****TEMP_SETUP***********/
tempSensor.begin();
/*****PHI + LCD_SETUP************/
pinMode(bkl_pin, OUTPUT);
digitalWrite(bkl_pin, HIGH);
lcd.begin(lcd_columns, lcd_rows);
init_phi_prompt(&lcd,keypads,function_keys, lcd_columns, lcd_rows, '~');
lcd.clear();
lcd.print("SETUP");
delay(2000);
/******ADDITIONAL_SETUP************/
//eeprom_clear();
//RTC.adjust(DateTime(__DATE__, __TIME__));
lcd.clear();
analogWrite(bkl_pin,bkl_IdleVal);
}
/******************************************/
// START of MAINLOOP
/******************************************/
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillisFive > 5000) {
previousMillisFive = currentMillis;
tempSensor.requestTemperatures();
getDate(&second, &minute, &hour, &day, &month, &year);
min_cnt = hour * 60 + minute;
LED_levels_output();
lcd.setCursor(0,0);
printHM(hour, minute);
lightPrint();
tempPrint();
}
int temp = wait_on_escape(50); // Use phi_keypads object to access the keypad
if (temp!=0) {top_menu();}
}
//**********************************************
//**********END of MAINLOOP*********************
//**********************************************