// Display UTFT
// Risoluzione 480x320 pixels.
// Board Arduino Mega 2560
// due to the size of the images.
// Librerie utilizzate:
// UTFT and UTouch libraries
// UTFT_Buttons add-on library.
//
//ESP8266
//PIN: RX D16
// TX D17
// RST RES
//
//COMPLETE CODE ON: https://andreacamilloni.000webhostapp.com/
//ultime modifiche: dove possibile eliminazione delay,funzione per antirimbalzo DR(pin),correzione variabili che allocavano memoria(da int a bool)
#define RELEASE 0 //release 0 se versione test
//release 1 versione rilasciata
// This code block is only needed to support multiple
// MCU architectures in a single sketch.
#if defined(__AVR__)
#define imagedatatype unsigned int
#elif defined(__PIC32MX__)
#define imagedatatype unsigned short
#elif defined(__arm__)
#define imagedatatype unsigned short
#endif
// End of multi-architecture block
//Librerie display HX8357B
#include <UTFT.h> //libreria per scrivere sul display
#include <UTouch.h> //libreria solo per display touch(non ussata)
#include <UTFT_Buttons.h> //libreria per la creazione di pulsanti
#include <UTFT_Geometry.h> //libreria per la creazione di figure geometriche
//librerie sensori
#include <DS1307.h> //rtc(RealTimeClock)
#include <dht11.h> //DHT11(Temperatura e umidit)
dht11 DHT; //dichiarazione per la successiva lettura dei parametri
#include <Wire.h> //ACCELEROMETRO
#define DHT11_PIN 2 //pin 2 DHT11
#define VT100_MODE 1 // Modalit seriale
//Sensore Ultrasuoni HCSR04
#define triggerPort 5 //pin 5 trigger
#define echoPort 6 //pin 6 echo
float distanza; //usata sia in ALLARME sia in MenuHcSR04 => distanza acquisita
float durata; //usata sia in ALLARME sia in MenuHcSR04 => durata BURST
int odistanza; //usata in ALLARME => stato precedente
bool stato_allarme[] = {false, false}; //usata in ALLARME
// Accelerometro MPU6050
const int MPU = 0x69; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ; //asse
// Sensore Temp. press. umid. BME280
#define BME280_ADDRESS 0x76 //I2C address del BME280
unsigned long int hum_raw, temp_raw, pres_raw; //umidit,temperatura,pressione
signed long int t_fine;
uint16_t dig_T1;
int16_t dig_T2;
int16_t dig_T3;
uint16_t dig_P1;
int16_t dig_P2;
int16_t dig_P3;
int16_t dig_P4;
int16_t dig_P5;
int16_t dig_P6;
int16_t dig_P7;
int16_t dig_P8;
int16_t dig_P9;
int8_t dig_H1;
int16_t dig_H2;
int8_t dig_H3;
int16_t dig_H4;
int16_t dig_H5;
int8_t dig_H6;
// fine parte BME280
// Gestione pulsanti
/*
int SW1 = DR(7); // "<<" Back
int SW2 = DR(8); // "<" Left
int SW3 = DR(9); // "v" Down
int SW4 = DR(10); // "^" Up
int SW5 = DR(11); // ">" Right
int SW6 = DR(12); // ">>" Enter
*/
//Funzione per lettura del fronte dei pulsanti
bool k, oldk;
bool DR(int pin)
{
oldk = k;
k = digitalRead(pin);
if (!k && oldk)
return false;
return true;
}//fine funzione
// Dichiarazione font usati
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
//extern uint8_t Dingbats1_XL[];
extern uint8_t SevenSegNumFont[]; //Solo numeri
// Dichiarazione bitmap usate
extern imagedatatype Nuvole[];
extern imagedatatype NuvoleSole[];
extern imagedatatype Sole[];
extern imagedatatype Pioggia[];
extern imagedatatype MatteiDEV_213[];
//dichiarazione modulo display HX8357B
UTFT myGLCD(HX8357B, 38, 39, 40, 41);
UTFT_Geometry geo(&myGLCD);
// Set up UTouch...
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino 2009/Uno/Leonardo shield : NOT SUPPORTED DUE TO LACK OF MEMORY
// Standard Arduino Mega/Due shield : 6,5,4,3,2
// CTE TFT LCD/SD Shield for Arduino Due : 6,5,4,3,2
// Standard chipKit Uno32/uC32 : 20,21,22,23,24
// Standard chipKit Max32 : 62,63,64,65,66
// AquaLEDSource All in One Super Screw Shield : 62,63,64,65,66
UTouch myTouch(52, 48, 51, 50, 49); //per display supportati
// Finally we set up UTFT_Buttons :)
UTFT_Buttons myButtons(&myGLCD, &myTouch);
int sensor_3V3 = A10;
int sensor_3V3_Value = 0;
float sensor_3V3_Volt = 0;
int sensor_VIN = A9;
int sensor_VIN_Value = 0;
float sensor_VIN_Volt = 0;
int sensor_LM35 = A8; //sensore temperatura LM35
int sensor_LM35_Value = 0;
int sensor_GAS = A12; //sensore gas
int GAS = 0;
int Allarme_GAS_PIN = 3;
int Allarme_GAS = 0;
float LM35_VIN_Volt = 0;
float Temperatura = 0;
float Lettura_DHT11;
int Index = 1;
int WeekDay;
//variabili per il controllo dello stato dei rele
bool stat_rele1 = false;
bool stat_rele2 = false;
// Init the DS1307 RTC
DS1307 rtc(20, 21); // I2C Mega 2560
Time t;
int but1, but2, but3, but4, but5, but6, butX, butY, pressed_button;
boolean default_colors = true;
void setup()
{
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(BigFont);
#if RELEASE //entra solamente se RELEASE == 1 e stampa inizialmente SENSORBOARD
myGLCD.setColor(VGA_RED);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("SENSOR BOARD", CENTER, (myGLCD.getDisplayYSize() / 2) - 8);
delay(5000);
myGLCD.clrScr();
#endif
// myTouch.InitTouch();
// myTouch.setPrecision(PREC_MEDIUM);
myButtons.setTextFont(BigFont);
//myButtons.setSymbolFont(Dingbats1_XL);
rtc.begin();
// Set the clock to run-mode
rtc.halt(false);
Serial.begin(9600);
Serial.println("Send any character to enter serial mode...");
Serial.println();
Serial2.begin(9600);//esp8266
// Gestione tastierino
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(18, OUTPUT);
pinMode( triggerPort, OUTPUT ); //Hcsr04_out
pinMode( echoPort, INPUT ); //Hcsr04_in
pinMode(13, OUTPUT); //LED
pinMode(14, OUTPUT); //Rele1
pinMode(15, OUTPUT); //Rele2
// Sensore BME280
uint8_t osrs_t = 1; //Temperature oversampling x 1
uint8_t osrs_p = 1; //Pressure oversampling x 1
uint8_t osrs_h = 1; //Humidity oversampling x 1
uint8_t mode = 3; //Normal mode
uint8_t t_sb = 5; //Tstandby 1000ms
uint8_t filter = 0; //Filter off
uint8_t spi3w_en = 0; //3-wire SPI Disable
uint8_t ctrl_meas_reg = (osrs_t << 5) | (osrs_p << 2) | mode;
uint8_t config_reg = (t_sb << 5) | (filter << 2) | spi3w_en;
uint8_t ctrl_hum_reg = osrs_h;
writeReg(0xF2, ctrl_hum_reg);
writeReg(0xF4, ctrl_meas_reg);
writeReg(0xF5, config_reg);
readTrim();
// fine Sensore BME 280
// Inizio Accelerometro MPU6050
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
// Fine Accelerometro MPU6050
//Configurazione bottoni menu principale
int but1, but2, but3, but4, but5, but6, but7, Icona, pressed_button; // touch
Icona = myButtons.addButton( 20, 20, 100, 75, MatteiDEV_213); // disegna logo
but1 = myButtons.addButton( 150, 20, 300, 30, "Altre Opzioni .."); //default
but2 = myButtons.addButton( 150, 60, 300, 30, "Dati Ambientali");
but3 = myButtons.addButton( 150, 100, 300, 30, "Avvisi ed Allarmi");
but4 = myButtons.addButton( 150, 140, 300, 30, "Centralina Meteo");
but5 = myButtons.addButton( 150, 180, 300, 30, "SET Data e Ora");
but6 = myButtons.addButton( 150, 220, 300, 30, "Monitor hardware");
myButtons.setButtonColors(VGA_RED, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
myButtons.drawButtons();
}
void printDate() // disegno calendario su pag. principale
{
Time t_temp;
t_temp = rtc.getTime();
myGLCD.setFont(BigFont);
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(255, 255, 255);
myGLCD.print(rtc.getDOWStr(FORMAT_SHORT), 40, 120);
if (rtc.getDOWStr(FORMAT_SHORT) == 1) // Scrivere calendario rosso se domenica.
myGLCD.setColor(VGA_RED);
else
myGLCD.setColor(0, 0, 0);
if (t_temp.date < 10)
myGLCD.printNumI(t_temp.date, 60, 140);
else
myGLCD.printNumI(t_temp.date, 40, 140);
myGLCD.print(rtc.getMonthStr(FORMAT_SHORT), 40, 160);
myGLCD.printNumI(t_temp.year, 35, 177);
}
void clearDate()
{
myGLCD.setColor(255, 255, 255);
myGLCD.fillRect(30, 118, 101, 195);
}
signed long int calibration_T(signed long int adc_T)
{
signed long int var1, var2, T;
var1 = ((((adc_T >> 3) - ((signed long int)dig_T1 << 1))) * ((signed long int)dig_T2)) >> 11;
var2 = (((((adc_T >> 4) - ((signed long int)dig_T1)) * ((adc_T >> 4) - ((signed long int)dig_T1))) >> 12) * ((signed long int)dig_T3)) >> 14;
t_fine = var1 + var2;
T = (t_fine * 5 + 128) >> 8;
return T;
}
unsigned long int calibration_P(signed long int adc_P) // BME280
{
signed long int var1, var2;
unsigned long int P;
var1 = (((signed long int)t_fine) >> 1) - (signed long int)64000;
var2 = (((var1 >> 2) * (var1 >> 2)) >> 11) * ((signed long int)dig_P6);
var2 = var2 + ((var1 * ((signed long int)dig_P5)) << 1);
var2 = (var2 >> 2) + (((signed long int)dig_P4) << 16);
var1 = (((dig_P3 * (((var1 >> 2) * (var1 >> 2)) >> 13)) >> 3) + ((((signed long int)dig_P2) * var1) >> 1)) >> 18;
var1 = ((((32768 + var1)) * ((signed long int)dig_P1)) >> 15);
if (var1 == 0)
{
return 0;
}
P = (((unsigned long int)(((signed long int)1048576) - adc_P) - (var2 >> 12))) * 3125;
if (P < 0x80000000)
{
P = (P << 1) / ((unsigned long int) var1);
}
else
{
P = (P / (unsigned long int)var1) * 2;
}
var1 = (((signed long int)dig_P9) * ((signed long int)(((P >> 3) * (P >> 3)) >> 13))) >> 12;
var2 = (((signed long int)(P >> 2)) * ((signed long int)dig_P8)) >> 13;
P = (unsigned long int)((signed long int)P + ((var1 + var2 + dig_P7) >> 4));
return P;
}
unsigned long int calibration_H(signed long int adc_H) // BME280
{
signed long int v_x1;
v_x1 = (t_fine - ((signed long int)76800));
v_x1 = (((((adc_H << 14) - (((signed long int)dig_H4) << 20) - (((signed long int)dig_H5) * v_x1)) +
((signed long int)16384)) >> 15) * (((((((v_x1 * ((signed long int)dig_H6)) >> 10) *
(((v_x1 * ((signed long int)dig_H3)) >> 11) + ((signed long int) 32768))) >> 10) + (( signed long int)2097152)) *
((signed long int) dig_H2) + 8192) >> 14));
v_x1 = (v_x1 - (((((v_x1 >> 15) * (v_x1 >> 15)) >> 7) * ((signed long int)dig_H1)) >> 4));
v_x1 = (v_x1 < 0 ? 0 : v_x1);
v_x1 = (v_x1 > 419430400 ? 419430400 : v_x1);
return (unsigned long int)(v_x1 >> 12);
}
/***********************************************************************************ALTREOPZIONI****************************************************ALTREOPZIONI***************************************************************/
void Menu1() // Sottomen altre opzioni
{
myGLCD.clrScr();
myButtons.deleteAllButtons();
int but1, but2, but3, but4, but5, but6, Icona, pressed_button; // touch
Icona = myButtons.addButton( 20, 20, 100, 75, MatteiDEV_213); // disegna logo
Index = 1;
but1 = myButtons.addButton( 150, 20, 300, 30, "Sensore Ultrasuoni"); //default
but2 = myButtons.addButton( 150, 60, 300, 30, "Dati Accelerometro");
but3 = myButtons.addButton( 150, 100, 300, 30, "Scan I2C Address");
but4 = myButtons.addButton( 150, 140, 300, 30, "Controllo Rele' ");
but5 = myButtons.addButton( 150, 180, 300, 30, "Connessione Web");
but6 = myButtons.addButton( 150, 220, 300, 30, "Informazioni");
myButtons.setButtonColors(VGA_RED, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
myButtons.drawButtons();
clearDate();
printDate(); //stampa DATA
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("IIS E. Mattei Recanati", 40, 270);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.setColor(VGA_BLACK);
myGLCD.print(" dip. Telecomunicazioni ", 25, 290);
// fine ricostruzione pagina iniziale
do
{
printHour(); //stampa ORA
//SW4 = DR(10); // "^" Up
//SW3 = DR(9); // "v" Down
if (!DR(10))
{
myButtons.disableButton(Index, true);
myButtons.setButtonColors(VGA_WHITE, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_BLUE);
Index--;
}
if (!DR(9))
{
myButtons.disableButton(Index, true);
myButtons.setButtonColors(VGA_WHITE, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_BLUE);
Index++;
}
// Ritardo per antirimbalzo su selezione men
if (Index > 6)
Index = 1;
if (Index < 1)
Index = 6;
//SW6 = DR(12); // Enter premuto
if (!DR(12))
switch (Index) {
case 1: // Sensore Ultrasuoni
butX == but1;
MenuDistanza();
break;
case 2: // Dati Accelerometro
butX == but2;
MenuAccelerometro();
break;
case 3: // Scan I2C Address
butX == but3;
MenuI2C();
break;
case 4: // Menu Rele
butX == but4;
MenuRele();
break;
case 5: // connessioneweb
butX == but5;
connessioneweb();
break;
case 6: // Informazioni
butX == but6;
informazioni(1.23, 1.4); // parametro1: versione firmware parametro2: versione hardware
break;
}
pressed_button == butX;
if (pressed_button == butX)
{
if (myButtons.buttonEnabled(Index))
{
myButtons.disableButton(Index, true);
myButtons.setButtonColors(VGA_YELLOW, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
}
else
{
myButtons.enableButton(Index, true);
myButtons.setButtonColors(VGA_YELLOW, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
}
}
} while (DR(7)); // Uscita sottomen
myButtons.deleteAllButtons();
myGLCD.clrScr();
Icona = myButtons.addButton( 20, 20, 100, 75, MatteiDEV_213); // disegna logo
but1 = myButtons.addButton( 150, 20, 300, 30, "Altre Opzioni .."); //default
but2 = myButtons.addButton( 150, 60, 300, 30, "Dati Ambientali");
but3 = myButtons.addButton( 150, 100, 300, 30, "Avvisi ed Allarmi");
but4 = myButtons.addButton( 150, 140, 300, 30, "Centralina Meteo");
but5 = myButtons.addButton( 150, 180, 300, 30, "SET Data e Ora");
but6 = myButtons.addButton( 150, 220, 300, 30, "Monitor hardware");
myButtons.setButtonColors(VGA_RED, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
myButtons.drawButtons();
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("IIS E. Mattei Recanati", 40, 270);
myGLCD.print(" dip. Telecomunicazioni ", 25, 290);
clearDate();
printDate();
// Ritorno pag. iniziale display LCD e ricostruzione Menu principale
// fine ricostruzione pagina iniziale
}
/***************************************************** Lettura*parametri*ambientali*************************************************/
void Menu2() // Lettura parametri ambientali
{
myGLCD.clrScr();
do
{
Allarme_GAS = digitalRead(3);
if (Allarme_GAS == LOW) {
myGLCD.setColor(VGA_YELLOW);
myGLCD.setBackColor(VGA_RED);
myGLCD.print(" ALLARME GAS ", 70, 50);
digitalWrite(18, 1);
}
else {
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_BLACK);
myGLCD.print(" ALLARME GAS ", 70, 50);
digitalWrite(18, 0);
}
sensor_LM35_Value = analogRead(sensor_LM35);
LM35_VIN_Volt = sensor_LM35_Value * 0.0048;
Temperatura = LM35_VIN_Volt * 100;
myGLCD.setBackColor(VGA_BLACK);
myGLCD.setColor(VGA_YELLOW);
myGLCD.print("Temperatura = ", 10, 110);
myGLCD.setColor(VGA_RED);
myGLCD.printNumF(Temperatura, 1, 230, 110);
myGLCD.setColor(VGA_YELLOW);
myGLCD.print("Gradi C.", 310, 110);
myGLCD.setColor(VGA_GRAY);
myGLCD.print("Valori Sensore LM35", 10, 80);
Lettura_DHT11 = DHT.read(DHT11_PIN); // Lettura dati DHT11
GAS = analogRead(sensor_GAS);
myGLCD.setColor(VGA_YELLOW);
myGLCD.print("Lettura sensore GAS = ", 10, 150);
myGLCD.setColor(VGA_BLACK);
myGLCD.print(" ", 360, 150); // cancella valore precedente
myGLCD.setColor(VGA_BLUE);
if (GAS <= 9)
myGLCD.printNumI(GAS, 390, 150);
if ((GAS >= 10) and (GAS < 100))
myGLCD.printNumI(GAS, 375, 150);
if ((GAS >= 100) and (GAS < 1000))
myGLCD.printNumI(GAS, 360, 150);
if (GAS >= 1000)
myGLCD.printNumI(GAS, 345, 150);
myGLCD.setColor(VGA_GRAY);
myGLCD.print("Dati sensore DHT11 ", 10, 190);
myGLCD.setColor(VGA_GREEN);
myGLCD.print("Valore Umidita' (%) = ", 10, 230);
myGLCD.print("Valore Temperatura = ", 10, 210);
myGLCD.setColor(VGA_PURPLE);
myGLCD.printNumF(DHT.humidity, 1, 360, 230);
myGLCD.printNumF(DHT.temperature, 1, 360, 210);
myGLCD.setColor(VGA_WHITE);
myGLCD.print(" Premere << per Uscire ", 10, 270);
} while (DR(7)); // Uscita pagina Parametri Ambientali
// Ritorno pag. iniziale display LCD
myGLCD.clrScr();
myButtons.setButtonColors(VGA_RED, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
myButtons.drawButtons();
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("IIS E. Mattei Recanati", 40, 270);
myGLCD.print(" dip. Telecomunicazioni ", 25, 290);
clearDate();
printDate();
// fine ricostruzione pagina iniziale
}
//*********************ALLARME*****************************************************************************ALLARME********
void Menu3() // Avvisi ed Allarmi
{
myGLCD.clrScr();
myButtons.deleteAllButtons();
int but1, but2, but3, but4, but5, but6, Icona, pressed_button; // touch
Index = 0;
myGLCD.setColor(VGA_RED);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print(" Allame Movimento ", 10, 10);
myGLCD.print(" Allame Vibrazioni ", 10, 180);
myGLCD.setColor(VGA_GREEN);
myGLCD.setBackColor(VGA_BLACK);
myGLCD.print("sensore ad ulrasuoni HCSR04", 10, 30);
myGLCD.print("sensore accelerometro MPU-6050", 10, 200);
but1 = myButtons.addButton( 10, 50, 186, 90, "ON"); //default
but2 = myButtons.addButton( 205, 50, 186, 90, "OFF");
but3 = myButtons.addButton( 10, 220, 186, 90, "ON"); //default
but4 = myButtons.addButton( 205, 220, 186, 90, "OFF");
myButtons.setButtonColors(VGA_RED, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
myButtons.drawButtons();
do
{
digitalWrite( triggerPort, LOW );
digitalWrite( triggerPort, HIGH );
delayMicroseconds( 10 );
digitalWrite( triggerPort, LOW );
durata = pulseIn( echoPort, HIGH );
distanza = 0.034 * durata / 2;
//DHT.read(DHT11_PIN);
//distanza = (331.4 + (0.62 * DHT.temperature)) / 10000 * durata;
//DR(11); // ">" Right
//DR(8); // "<" Left
if (!DR(8))
{
myButtons.disableButton(Index, true);
myButtons.setButtonColors(VGA_WHITE, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_BLUE);
Index--;
}
if (!DR(11))
{
myButtons.disableButton(Index, true);
myButtons.setButtonColors(VGA_WHITE, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_BLUE);
Index++;
}
// Ritardo per antirimbalzo su selezione men
if (Index > 3)
Index = 0;
if (Index < 0)
Index = 3;
//SW6 = DR(12); // Enter premuto
if (!DR(12))
switch (Index) {
case 0: //on
butX == but1;
odistanza = distanza;
stato_allarme[0] = true;
break;
case 1: //off
butX == but2;
stato_allarme[0] = false;
break;
case 2:
butX == but3;
// Wire.beginTransmission(MPU);
// Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
// Wire.endTransmission(false);
// Wire.requestFrom(MPU, 14, true); // request a total of 14 registers
// AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
// AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
// AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
// GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
// GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
// GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
stato_allarme[1] = true;
break;
case 3: //off
butX == but4;
stato_allarme[1] = false;
break;
}
pressed_button == butX;
if (pressed_button == butX)
{
if (myButtons.buttonEnabled(Index))
{
myButtons.disableButton(Index, true);
myButtons.setButtonColors(VGA_YELLOW, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
}
else
{
myButtons.enableButton(Index, true);
myButtons.setButtonColors(VGA_YELLOW, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
}
}
Allarme();
} while (DR(7)); // Uscita sottomen
myButtons.deleteAllButtons();
myGLCD.clrScr();
Icona = myButtons.addButton( 20, 20, 100, 75, MatteiDEV_213); // disegna logo
but1 = myButtons.addButton( 150, 20, 300, 30, "Altre Opzioni .."); //default
but2 = myButtons.addButton( 150, 60, 300, 30, "Dati Ambientali");
but3 = myButtons.addButton( 150, 100, 300, 30, "Avvisi ed Allarmi");
but4 = myButtons.addButton( 150, 140, 300, 30, "Centralina Meteo");
but5 = myButtons.addButton( 150, 180, 300, 30, "SET Data e Ora");
but6 = myButtons.addButton( 150, 220, 300, 30, "Monitor hardware");
myButtons.setButtonColors(VGA_RED, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
myButtons.drawButtons();
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("IIS E. Mattei Recanati", 40, 270);
myGLCD.print(" dip. Telecomunicazioni ", 25, 290);
clearDate();
printDate();
}
void Allarme()
{
if (stato_allarme[0])
if ((odistanza - distanza) > 3 || (odistanza - distanza) < -3 )
{
stat_rele1 = true;//stato rele generale
digitalWrite(14, stat_rele1);
digitalWrite(18, stat_rele1);
myGLCD.setColor(VGA_YELLOW);
myGLCD.setBackColor(VGA_RED);
myGLCD.print(" ATTENZIONE ", 10, 150);
}
if (!stato_allarme[0]) {
stat_rele1 = false;//stato rele generale
digitalWrite(14, stat_rele1);
digitalWrite(18, stat_rele1);
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_BLACK);
myGLCD.print(" ATTENZIONE ", 10, 150);
}
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_BLACK);
}
//*****************************METEO*******************************************METEO*********************************METEO*************
void Menu4() // Centralina Meteo Sensore BME280
{
myButtons.deleteAllButtons();
myGLCD.clrScr();
myGLCD.setColor(VGA_RED);
//myGLCD.drawRect(10, 14, 465, 90);
int but1, but2, but3, but4, but5, but6, Icona, pressed_button; // touch
do
{
double temp_act = 0.0, press_act = 0.0, hum_act = 0.0;
signed long int temp_cal;
unsigned long int press_cal, hum_cal;
readData();
temp_cal = calibration_T(temp_raw);
press_cal = calibration_P(pres_raw);
hum_cal = calibration_H(hum_raw);
temp_act = (double)temp_cal / 100.0;
press_act = (double)press_cal / 100.0;
hum_act = (double)hum_cal / 1024.0;
myGLCD.setColor(VGA_YELLOW);
myGLCD.setBackColor(VGA_BLACK);
myGLCD.print("TEMP. = ", 30, 150);
myGLCD.print("DegC", 250, 150);
myGLCD.setColor(VGA_BLUE);
myGLCD.printNumF(temp_act, 2, 150, 150);
myGLCD.setColor(VGA_RED);
myGLCD.print("Pressione = ", 30, 190);
myGLCD.print("mBAR ", 350, 190);
myGLCD.setColor(VGA_GRAY);
myGLCD.printNumF(press_act, 2, 230, 190);
myGLCD.setColor(VGA_GREEN);
myGLCD.print("Umidita' = ", 30, 230);
myGLCD.print(" % ", 320, 230);
myGLCD.setColor(VGA_YELLOW);
myGLCD.printNumF(hum_act, 2, 220, 230);
//int Icona;
String stringaMeteo;
String stringaMeteo1;
if (press_act < 984 && hum_act > 65)//pioggia press1010
{ myButtons.deleteAllButtons();
myButtons.addButton( 30, 20, 72, 72, Pioggia); // disegna logo
stringaMeteo = "Pioggia ";
//delay(25);
}
if (press_act < 984 && hum_act < 65)//nuvoloso press1010
{
myButtons.deleteAllButtons();
myButtons.addButton( 30, 20, 72, 72, Nuvole); // disegna logo
//delay(25);
stringaMeteo = "Nuvoloso ";
}
if (press_act > 984 && hum_act > 65)//schiarite press1010
{
myButtons.deleteAllButtons();
myButtons.addButton( 30, 20, 72, 72, NuvoleSole);
//delay(25);
stringaMeteo = "Parzialmente";
stringaMeteo1 = "Nuvoloso";
} else stringaMeteo1 = " ";
if (press_act > 984 && hum_act < 65)//sole press1010
{ myButtons.deleteAllButtons();
myButtons.addButton( 30, 20, 72, 72, Sole);
//delay(25);
stringaMeteo = "Soleggiato ";
}
myGLCD.setColor(VGA_RED);
myGLCD.setBackColor(VGA_GREEN);
myGLCD.print("LIVE METEO", 120, 25);
myGLCD.setColor(VGA_GREEN);
myGLCD.setBackColor(VGA_BLACK);
myGLCD.print(stringaMeteo, 120, 70);
myGLCD.print(stringaMeteo1, 120, 90);
lum();
myGLCD.setFont(SmallFont);
myGLCD.setColor(VGA_YELLOW);
myGLCD.print("Luminosita'", 360, 30);
myButtons.drawButtons();
myGLCD.setFont(BigFont);
myGLCD.setColor(VGA_WHITE);
myGLCD.print(" Premere << per Uscire ", 10, 270); // Uscire da Centralina Meteo
} while (DR(7)); // Uscita pagina 6
myButtons.deleteAllButtons();
myGLCD.clrScr();
Icona = myButtons.addButton( 20, 20, 100, 75, MatteiDEV_213); // disegna logo
but1 = myButtons.addButton( 150, 20, 300, 30, "Altre Opzioni .."); //default
but2 = myButtons.addButton( 150, 60, 300, 30, "Dati Ambientali");
but3 = myButtons.addButton( 150, 100, 300, 30, "Avvisi ed Allarmi");
but4 = myButtons.addButton( 150, 140, 300, 30, "Centralina Meteo");
but5 = myButtons.addButton( 150, 180, 300, 30, "SET Data e Ora");
but6 = myButtons.addButton( 150, 220, 300, 30, "Monitor hardware");
myButtons.setButtonColors(VGA_RED, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
myButtons.drawButtons();
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("IIS E. Mattei Recanati", 40, 270);
myGLCD.print(" dip. Telecomunicazioni ", 25, 290);
clearDate();
printDate();
// Ritorno pag. iniziale display LCD e ricostruzione Menu principale
// fine ricostruzione pagina iniziale
}
//********************************************************DATA&ORA*****************************DATA&ORA*****************DATA&ORA****
void Menu5() // SET Data e Ora
{
myGLCD.clrScr();
setClock();
do
{
myGLCD.setColor(VGA_WHITE);
myGLCD.print(" Premere << per Uscire ", 10, 260);
myGLCD.print(" Premere >> per Salvare ", 10, 290);
} while (DR(7)); // Uscita pagina 6
// Ritorno pag. iniziale display LCD
myGLCD.clrScr();
// myButtons.addButton( 20, 20, 100, 75, MatteiDEV_213); // disegna logo
myButtons.setButtonColors(VGA_RED, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
myButtons.drawButtons();
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("IIS E. Mattei Recanati", 40, 270);
myGLCD.print(" dip. Telecomunicazioni ", 25, 290);
clearDate();
printDate();
// fine ricostruzione pagina iniziale
}
//**************MONITOR_HARDWARE************************MONITOR_HARDWARE*******************************MONITOR_HARDWARE****
void Menu6() // Monitor hardware
{
myGLCD.clrScr();
myGLCD.drawRect(10, 14, 225, 150);
myGLCD.print(" TEST BUTTON ", 11, 15);
myGLCD.setColor(VGA_GRAY);
myGLCD.print("MONITOR TENSIONI", 11, 161);
myGLCD.drawRect(10, 250, 285, 160);
do
{
myGLCD.setColor(VGA_WHITE);
myGLCD.setColor(VGA_RED);
if (!DR(7))
{ myGLCD.setColor(VGA_RED);
myGLCD.print("<<", 30, 100);
}
else {
myGLCD.setColor(VGA_WHITE);
myGLCD.print("<<", 30, 100);
}
if (!DR(8)) {
myGLCD.setColor(VGA_RED);
myGLCD.print("<", 80, 100);
}
else {
myGLCD.setColor(VGA_WHITE);
myGLCD.print("<", 80, 100);
}
if (!DR(10)) {
myGLCD.setColor(VGA_RED);
myGLCD.print("^", 110, 85);
}
else {
myGLCD.setColor(VGA_WHITE);
myGLCD.print("^", 110, 85);
}
if (!DR(9)) {
myGLCD.setColor(VGA_RED);
myGLCD.print("v", 110, 115);
}
else {
myGLCD.setColor(VGA_WHITE);
myGLCD.print("v", 110, 115);
}
if (!DR(11)) {
myGLCD.setColor(VGA_RED);
myGLCD.print(">", 140, 100);
}
else {
myGLCD.setColor(VGA_WHITE);
myGLCD.print(">", 140, 100);
}
if (!DR(12)) {
myGLCD.setColor(VGA_RED);
myGLCD.print(">>", 175, 100);
}
else {
myGLCD.setColor(VGA_WHITE);
myGLCD.print(">>", 175, 100);
}
sensor_3V3_Value = analogRead(sensor_3V3);
sensor_VIN_Value = analogRead(sensor_VIN);
sensor_3V3_Volt = sensor_3V3_Value * 0.0050;
sensor_VIN_Volt = sensor_VIN_Value * 0.0051;
sensor_VIN_Volt = sensor_VIN_Volt * 4.1; // Partitore resistivo in ingresso
myGLCD.setColor(VGA_YELLOW);
myGLCD.setBackColor(VGA_BLACK);
myGLCD.print("Valore 3V3 = ", 11, 200);
myGLCD.setColor(VGA_RED);
myGLCD.print("Valore VIN = ", 11, 220);
myGLCD.setColor(VGA_BLUE);
myGLCD.printNumF(sensor_3V3_Volt, 2, 220, 200);
myGLCD.printNumF(sensor_VIN_Volt, 2, 220, 220);
myGLCD.setColor(VGA_WHITE);
myGLCD.print(" Premere << per uscire ", 10, 270);
} while (DR(7)); // Uscita pagina 6
// Ritorno pag. iniziale display LCD
myGLCD.clrScr();
myButtons.setButtonColors(VGA_RED, VGA_RED, VGA_BLACK, VGA_BLUE, VGA_GRAY);
myButtons.drawButtons();
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("IIS E. Mattei Recanati", 40, 270);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.setColor(VGA_BLACK);
myGLCD.print(" dip. Telecomunicazioni ", 25, 290);
clearDate();
printDate();
// fine ricostruzione pagina iniziale
}
/*********LOOP*******LOOP**********LOOP***********LOOP*************LOOP************LOOP*********LOOP********LOOP********LOOP*************/
void loop()
{
clearDate();
printDate();
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.print("IIS E. Mattei Recanati", 40, 270);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.setColor(VGA_BLACK);
myGLCD.print(" dip. Telecomunicazioni ", 25, 290);
Index = 1;
while (1) // *********** LOOP Principale ************
{
...
This file has been truncated, please download it to see its full contents.
Comments