ciao nid69ita scusame se gia non lo avevo fatto ma ero nuovo nel forum!
uwefed devo cambiare tutti i delay con millis?
ora ti posto i due programmi da unire:
***********************************************
* PROGRAMMA SENSORI DISTANZA *
***********************************************
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 10, 5, 4, 3, 2);
int level;
int pingPin = 11; //output 10us pulse to this pin
int inPin = 13; //measure return pulse width from this pin
long duration, inches, cm;
int indec, cmdec, leveldec;
int inchconv = 147; // ratio between puls width and inches
int cmconv = 59; // ratio between pulse width and cm
String s1, s2;
void setup() {
lcd.begin(16,2);
lcd.print("Dmalab ver.1.0");
lcd.setCursor(0,1);
lcd.print("Water level ");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Develpment by ");
lcd.setCursor(0,1);
lcd.print("Marchetti");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("29/12/2014");
delay(2000);
lcd.clear();
pinMode(pingPin, OUTPUT);
pinMode(inPin, INPUT);
}
void loop()
{
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
duration = pulseIn(inPin, HIGH);
cm = microsecondsToCentimeters(duration);
cmdec = (duration - cm * cmconv) * 10 / cmconv;
level = (cm*1.53);
s2 = String(level) +"."+String(leveldec) +"%"+" ";
lcd.setCursor(0,0);
lcd.print("Livello");
lcd.setCursor(8,0);
lcd.print(s2);
delay(500);
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / cmconv;
}
***********************************************
* PROGRAMMA TIMER *
***********************************************
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,10,9,8,7);
int runTimer = 1;
int runFor = 6; // time in seconds
int buzzerPin = 13;
int relayPin=4;
int data = 0;
int stato = 0;
void setup() {
boolean stato = false;
pinMode(2, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(relayPin,OUTPUT);
lcd.begin(16, 2);
}
void loop()
{
if (digitalRead(2)==HIGH){
if (stato == false){
stato = true;}
if (stato == true){
if(runTimer == 1){
digitalWrite(relayPin,LOW);
// relay is OFF during countdown
/* *change to HIGH if you want the relay to be ON while countdowning */
lcd.clear();
lcd.print("TIMER=");
//Start timer
timer();
} else {
digitalWrite(relayPin,HIGH); // relay is ON when time expired
/* *change to LOW if you want the relay to be OFF when the time expired */
}
runTimer = 0;
lcd.noDisplay();
delay(250);
lcd.display();
delay(250);
}
}
}
void timer() {
for(int timer = runFor;timer > 0; --timer){
if(timer >= 10) {
lcd.setCursor(6,0);
} else {
lcd.setCursor(6,0);
lcd.print("0");
lcd.setCursor(7,0);
}
lcd.print(timer);
delay(1000);
}
lcd.setCursor(0,0);
lcd.clear();
lcd.print(" CFINE DOCCIA");
}
COME FACCIO PER FARLI FUNZIONARE INSIEME?
GRAZIE