ragazzi sono nuovamente qui per chiedere il vostro aiuto
ho arduino mega 2560 con RTC display lcd 20x4 e sonda stagna temp DS18B20 perfettamente tutto funzionante e da qualche tempo stavo riflettendo di mettere un buzzer e led che mi intervengono ad una determinata temperatura e che magari al rientrare della stessa smetta di suonare.
Pero' non riesco a far interagire le due cose cioe' non riesco ad integrare al mio sketch che indico di sotto il buzzer e il led (magari se possibile inserire un pulsante di tacitazione)considerando che il buzzer è collegato al pin 8 e il led al pin 13 riuscite a darmi una mano ?
Ringrazio anticipatamente per le risposte.
#include "Wire.h"
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <LiquidCrystal.h>
#define DS1307_I2C_ADDRESS 0x68
#define BUTTON A0
int DS18B20_Pin = 6;
float temperature = 0.0;
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
OneWire ds(DS18B20_Pin);
void setup() {
Wire.begin();
Serial.begin(9600);
lcd.begin(20, 4);
// Modificare i seguenti valori per impostare il vostro orologio ad ogni avvio del programma.
// Probabilmente si desidera impostare solo l'orologio una volta e quindi rimuovere
// la chiamata setDateDs1307 .
// second = 00;
// minute = 04;
// hour = 01;
// dayOfWeek = 5;
// dayOfMonth = 27;
// month = 6;
// year = 14;
// setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);// chiamata per settare l'orologio
}
void loop() {
temperature = getTemp();
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.clear(); // clear LCD screen
lcd.setCursor(1,0); // prima riga ---> www DD/MM/YYYY
switch(dayOfWeek){
case 1:
lcd.print("Lunedi");
break;
case 2:
lcd.print("Martedi");
break;
case 3:
lcd.print("Mercoledi");
break;
case 4:
lcd.print("Giovedi");
break;
case 5:
lcd.print("Venerdi");
break;
case 6:
lcd.print("Sabato");
break;
case 7:
lcd.print("Domenica");
break;
}
lcd.print(" ");
lcd.print(dayOfMonth, DEC);
lcd.print("/");
if (month < 10) lcd.print("0");
lcd.print(month, DEC);
lcd.print("/20");
lcd.print(year, DEC);
lcd.setCursor(4,1); // seconda riga ---> orario hh.min.sec
lcd.print("ore");
lcd.print(" ");
lcd.print(hour, DEC);
lcd.print(".");
if (minute < 10) lcd.print("0");
lcd.print(minute, DEC);
lcd.print(".");
if (second < 10) lcd.print("0");
lcd.print(second, DEC);
lcd.setCursor(0,3); // quarta riga
lcd.print("Temp:");
lcd.print(temperature);
Serial.println(temperature);
delay(1000);
}
float getTemp() { //returns the temperature from one DS18B20 in DEG Celsius
byte data[12];
byte addr[8];
if (!ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if (addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
byte decToBcd(byte val) { // Convert normal decimal numbers to binary coded decimal
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) { // Convert binary coded decimal to normal decimal numbers
return ((val/16*10) + (val%16));
}
// Stops the DS1307, but it has the side effect of setting seconds to 0
// Probably only want to use this for testing
void stopDs1307() {
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(0x80);
Wire.endTransmission();
}
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour)); // If you want 12 hour am/pm you need to set
// bit 6 (also need to change readDateDs1307)
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}