Standardoil:
dovrebbe uscirti sempre scritto "StatoRele 1"
ti torna?
questo mi tornava... ma poi invece di leggere 1 volevo leggere on..
Standardoil:
non mi è chiaro come faccia ad andare, una cosa del genere
hai cgreato due variabili puntatore a stringa, inizializzato in una maniera fantasiosa, ma fantasiosa forte
ammenocche' non siano due array di Stringa, con un solo elemento, inizializzati a stringa costante
e le usi per assegnarle a una variabile che non sappiamo di che tipo sia, ma presumo bool o int
due domande:
ma compila, sta roba?
intendo sul serio, guarda bene cosa ti dice in compilazione, che magari imparo qualcosa di nuovo
comunque se compilasse e statorele fosse boolean forse qualcosa avviene, nel senso che Str1 ed Str2 sono nomi di array, quindi puntatori, che se non NULL, ovvero sono validi, vengono interpretati come true
avevo scritto che era un riassunto..
Standardoil:
metti il codcie completo, dai
eccolo
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#define pwmPin 11// pin pwm sensore
SoftwareSerial mySerial(A2, A1); // RX, TX
LiquidCrystal lcd(8, 9, 4, 5, 6,7);
byte schermatainiziale = 0;
byte cmd[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};
unsigned char response[9];
unsigned long th, tl,ppm, ppm2, ppm3 = 0;
const int RELAY=12; //Lock Relay or motor
const int pulsante = 13 ;
int buttonState= LOW; // the current reading from the input pin
int lastButtonState = 0; // the previous reading from the input pin
boolean RS1 = false;
boolean RS2 = false;
boolean RSok = false;
long previousMillis = 0;
long interval = 6000;
unsigned long mymillis;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 30; // the debounce time; increase if the output flickers
int SetPoint=1000;
int luce=10;//luce display
int analogPin = A0;// pin dei pulsanti
int statorele = 0;
int adc_key_in = 0;
#define dx 0
#define su 1
#define giu 2
#define sx 3
#define SELECT 4
#define btnNONE 5
int val = 1;
int read_buttons() {
int adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50) return dx;
if (adc_key_in < 195) return su;
if (adc_key_in < 380) return giu;
if (adc_key_in < 555) return sx;
if (adc_key_in < 790) return SELECT;
}
char on[]= "ON" ;
char off[]= "OFF";
void setup() {
Serial.begin(9600);
// Initializes and clears the LCD screen
lcd.begin(16, 2);
lcd.clear();
mySerial.begin(9600);
pinMode(pwmPin, INPUT);
pinMode(luce,OUTPUT);
pinMode(RELAY,OUTPUT);
pinMode (pulsante,INPUT);
//digitalWrite(su,LOW);
//digitalWrite(giu,LOW);
digitalWrite(RELAY,LOW);
digitalWrite(luce,HIGH);
lcd.clear();
lcd.setCursor (0,0);
lcd.print( "CONTROLLORE CO2");
lcd.setCursor(0,1) ;
lcd.print( "CIRO MATACENA" );
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PRERISCALDAMENTO");
lcd.setCursor(0,1) ;
lcd.print( "SENSORE CO2");
delay(1000);
lcd.clear();
}
void loop() {
if (millis() - previousMillis > 30000 & schermatainiziale == 0) {lcd.clear(); lcd.home(); schermatainiziale = 1;}
statorele=digitalRead(RELAY);
if(statorele==1)statorele=on;
else statorele=off;
if (millis()- previousMillis < interval){
lcd.setCursor(0,0);
lcd.print(" Inizializzazione "); // viene eseguita una sola volta
lcd.setCursor(1,2);
lcd.print("Elapse Time : ");
lcd.print(millis()/1000.0);
RS1 = true; // Suggerimento Orso2001 indispensabile per la commutazione
delay(2000);
}
lcd.setCursor(0,0);
lcd.print("CO2:");
lcd.print(ppm );lcd.print(" ");
lcd.print("ppm");
lcd.setCursor(0,1);
lcd.print("SetPoint:");
lcd.print(SetPoint);
lcd.print("ppm ");
//**deve entrare in loop da questo punto commutando 2 e 3 schermata senza interferire a livello di delay
//con la lettura di vari sensori presenti nel programma esteso, codice omesso per brevità.
if (millis()- previousMillis >interval) {
if (RS1 == true && RSok == false) {
//disegna seconda schermata
lcd.setCursor(0,1);
lcd.print (" Stato Rele"); lcd.print(" "); lcd.print(statorele);lcd.print(" ");
delay(2000);
RSok = true;
mymillis = millis();
}
if (RS2 == true && RSok == false) {
//disegna terza schermata
RSok = true;
mymillis = millis();
}
if (millis() - mymillis >= 8000) { //ogni 4 secondi eseguo....
RS1 = !RS1;
RS2 = !RS2;
RSok = false;
}
}
int buttons = read_buttons();
// buttonState= digitalRead(pulsante);
/*if(Serial.available()){
char comando = Serial.read();
if(comando == 'a'){
digitalWrite(RELAY, HIGH);
Serial.println("LED acceso");
}
else if(comando == 's'){
digitalWrite(RELAY, LOW);
Serial.println("LED spento");
}
else{
Serial.println("Comando non riconosciuto");
}
//delay(10);
}
/*
/*if (buttons != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
lastButtonState=buttons;
}*/
mySerial.write(cmd,9);
mySerial.readBytes(response, 9);
unsigned int responseHigh = (unsigned int) response[2];
unsigned int responseLow = (unsigned int) response[3];
ppm = (256*responseHigh)+responseLow;
//CO2 via pwm
//do {
// th = pulseIn(pwmPin, HIGH, 1004000) / 1000;
// tl = 1004 - th;
// ppm2 = 2000 * (th-2)/(th+tl-4);
// ppm3 = 5000 * (th-2)/(th+tl-4);
// } while (th == 0);
if(ppm > SetPoint){
digitalWrite(RELAY,LOW);
}
else digitalWrite(RELAY,HIGH); //Turn on heater
if(buttons==giu)
//if(buttonState==HIGH)
{
if(SetPoint>0)
{
SetPoint--;
}
}
if(buttons==su)
{
if(SetPoint<2000)
{
SetPoint= SetPoint+val;
}
}
Serial.println(ppm);
Serial.println(th);
Serial.println(ppm2);
Serial.println(ppm3);
if(buttons == dx) digitalWrite(luce,LOW);
else if(buttons == sx) digitalWrite(luce,HIGH);
delay(100); //Update at every 100mSeconds
}