Albo może jest inaczej... developer w trakcie rehabilitacji, a Arduino + moduły płyną od ping-pongów
![Wink ;)](https://alkohole-domowe.com/forum/images/smilies/icon_e_wink.gif)
Witam, spróbuj tak:crobe pisze:Ja muszę wykombinować jak zapisać adresy DS do EPROM. Resztę chyba bym dał rade
Kod: Zaznacz cały
typedef struct {
uint8_t[8] ds_head,
uint8_t[8] ds_keg,
uint8_t[8] ds_process
} DS_Config;
DS_Config EEMEM ee_ds_config;
DS_Config ds_config;
Kod: Zaznacz cały
eeprom_read_block(&ee_ds_config, &ds_config, sizeof(ds_config));
Kod: Zaznacz cały
eeprom_write_block(&ds_config, &ee_ds_config, sizeof(ds_config));
Kod: Zaznacz cały
EEPROM.put(eeAddress, ds_config);
Kod: Zaznacz cały
//#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define ile_czujnikow 2 //ilosc podlaczonych czujnikow
#define alarm_treshold 0.1
#define relay_treshold 0.3
#define ONE_WIRE_BUS 10 //maagistrala onewire pin 10
#define reference_pin 12 //klawisz ustawiania wartosci referencyjnej podpiety pod pin 12
#define reset_pin 11 //klawisz resetowania wartosci referencyjnej podpiety pod pin 7
#define relay_pin 9 //przekaznik elektrozaworu podpiety pod pin 9
#define buzzer_pin 8
OneWire magistrala(ONE_WIRE_BUS);
DallasTemperature sensors(&magistrala);
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
DeviceAddress adresy [ile_czujnikow] =
{ 0x28, 0xFF, 0x43, 0xB7, 0x82, 0x16, 0x3, 0x71, //adresy czujnikow - ustawic wlasne
0x28, 0xFF, 0x41, 0x58, 0x82, 0x16, 0x5, 0xFC
};
byte symbol[8] = {
0b00110,
0b01001,
0b01001,
0b00110,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup() {
pinMode (reference_pin, INPUT_PULLUP);
pinMode (reset_pin, INPUT_PULLUP);
pinMode (relay_pin, OUTPUT);
pinMode (buzzer_pin, OUTPUT);
digitalWrite (relay_pin, LOW);
digitalWrite (buzzer_pin, LOW);
lcd.begin(20, 4);
lcd.createChar (0, symbol);
lcd.home();
lcd.print (F("10'th:")); //tu mozna wstawic wlasna nazwe czujnika //wyswietlenie stalych tekstĂłw na wyswietlaczu w celu oszczedzenia czasu procesora
lcd.setCursor (18, 0); //
lcd.print(char(0));
lcd.print(F("C"));
lcd.setCursor(0, 1);
lcd.print (F("Head:")); ////tu mozna wstawic wlasna nazwe czujnika
lcd.setCursor (18, 1);
lcd.print(char(0));
lcd.print(F("C"));
lcd.setCursor(0, 3);
lcd.print (F("Ref:")); ////tu mozna wstawic wlasna nazwe czujnika
lcd.setCursor (18, 3);
lcd.print(char(0));
lcd.print(F("C"));
sensors.begin();
sensors.setResolution (12);
}
void loop() {
float mean;
static float reference = 100;
byte wiersz = 0;
float temperatura;
sensors.requestTemperatures();
for (wiersz = 0; wiersz < ile_czujnikow; wiersz++)
{
temperatura = (sensors.getTempC(adresy [wiersz]));
display_temp (&temperatura, 12, wiersz);
if (wiersz == 0) {
mean = obliczSrednia(temperatura);
if (digitalRead(reference_pin) == LOW)
{
reference = mean;
// digitalWrite (relay_pin, LOW);
}
if (digitalRead (reset_pin) == LOW)
{
digitalWrite (buzzer_pin, LOW);
digitalWrite (relay_pin, LOW);
}
if (mean > (reference + alarm_treshold)) digitalWrite (buzzer_pin, HIGH);
if (mean > (reference + relay_treshold)) digitalWrite (relay_pin, HIGH);
//display_temp (&mean, 12, 2);
display_temp (&reference, 12, 3);
}
}
}
//delay (300);
void display_temp(float *value, byte column, byte row) //funkcja wyswietla wartosc value w kolumnie column i wierszu row
{
char outstr[9];
//value = value + corr[wiersz];
*value = round (*value * 100);
*value = (*value / 100.0);
dtostrf(*value, 6, 2, outstr); //wyswieltenie bo 2 miejsc po przecinku
lcd.setCursor(column, row);
lcd.print(outstr);
}
float obliczSrednia (float svalue) //svalue to wynik jednego pomiaru (SingleValue)
{
#define z_ilu_srednia 3
static byte k; //numer pomiaru, albo inaczej pozycja w tablicy
byte i;
float mvalue = 0.0; //zmienna przechowujaca wartosc sredniej
static float values [z_ilu_srednia]; //tablica przechowujaca wyniki n ostatnich pomiarow
if (k > (z_ilu_srednia - 1)) k = 0;
values [k] = svalue;
k++;
for (i = 0; i < z_ilu_srednia; i++)
mvalue = mvalue + values [i];
mvalue = mvalue / z_ilu_srednia;
return (mvalue);
}
Kod: Zaznacz cały
{
1. rozpocznij konwersje
2. zapisz bieżący stan time_milis()
{tutaj obsługa wyświetlacza, przycisków etc;
policzenie średnich, zapamiętanie wartości referencyjnej
sprawdź czy minęło 750 ms, jeśli nie, zajmuj sie dalej obsługą wyświetlacza etc.
}
odczytaj termometry, umieść wyniki w tablicy i wróć na początek.
}
Kod: Zaznacz cały
void DallasTemperature::requestTemperatures()
{
_wire->reset();
_wire->skip();
_wire->write(STARTCONVO, parasite);
// ASYNC mode?
if (!waitForConversion) return;
blockTillConversionComplete(&bitResolution, 0);
return;
}
Kod: Zaznacz cały
void DallasTemperature::blockTillConversionComplete(uint8_t* bitResolution, uint8_t* deviceAddress)
{
if(deviceAddress != 0 && checkForConversion && !parasite)
{
// Continue to check if the IC has responded with a temperature
// NB: Could cause issues with multiple devices (one device may respond faster)
unsigned long start = millis();
while(!isConversionAvailable(0) && ((millis() - start) < 750));
}
// Wait a fix number of cycles till conversion is complete (based on IC datasheet)
switch (*bitResolution)
{
case 9:
delay(94);
break;
case 10:
delay(188);
break;
case 11:
delay(375);
break;
case 12:
default:
delay(750);
break;
}
}
Kod: Zaznacz cały
#include <EEPROMex.h>
#include <EEPROMVar.h>
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <avr/wdt.h>
#define ONE_WIRE_BUS 8
#define TEMPERATURE_PRECISION 12
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress czuj1, czuj2, czuj3;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long previousMillis = 0;
//ZMIENNE WARTOSCI MENU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int menuin = 0;
int menu = 1;
float val = 0;
float valold = 0;
//#########################################################################################################################################################################################
//ZMIENNE KLAWIATURY /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int klaw;
int klawold;
int kwart;
int klawsek = 0;
//#########################################################################################################################################################################################
float temp1;
float temp1min = 20;
float temp1max = 90;
float temp2;
float temp2min = 30 ;
float temp2max = 100;
float temp3;
float temp3min = 40;
float temp3max = 110 ;
int al1 = 0;
int al2 = 0;
int al3 = 0;
int ton = 0;
int dzwiek = 0;
int al1stan = 0;
int al2stan = 0;
int al3stan = 0;
int al1min = 0;
int al1max = 0;
int al2min = 0;
int al2max = 0;
int al3min = 0;
int al3max = 0;
unsigned long czas;
int klawsek1;
byte st1[8] = {
0b01000,
0b10100,
0b01000,
0b00011,
0b00100,
0b00100,
0b00100,
0b00011
};
byte st2[8] = {
0b01110,
0b01110,
0b01110,
0b01110,
0b01110,
0b00000,
0b01110,
0b01110
};
byte al[8] = {
0b00010,
0b00101,
0b00111,
0b00101,
0b10000,
0b10000,
0b10000,
0b11100
};
byte b1[8] = {
0b00001,
0b00001,
0b00001,
0b00001,
0b00001,
0b00001,
0b00001,
0b00001
};
byte b2[8] = {
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000
};
byte b3[8] = {
0b01010,
0b01011,
0b01010,
0b01010,
0b01011,
0b01000,
0b01011,
0b01111
};
byte b4[8] = {
0b01010,
0b10010,
0b01010,
0b01010,
0b10010,
0b00010,
0b11010,
0b11110
};
void setup() {
wdt_enable(WDTO_4S);
sensors.begin();
sensors.getAddress(czuj1, 0);
sensors.getAddress(czuj2, 1);
sensors.getAddress(czuj3, 2);
sensors.setResolution(czuj1, TEMPERATURE_PRECISION);
sensors.setResolution(czuj2, TEMPERATURE_PRECISION);
sensors.setResolution(czuj3, TEMPERATURE_PRECISION);
sensors.setWaitForConversion(false);
lcd.begin(16, 2);
lcd.clear();
lcd.createChar(1, st1);
lcd.createChar(2, st2);
lcd.createChar(3, al);
lcd.createChar(4, b1);
lcd.createChar(5, b2);
lcd.createChar(6, b3);
lcd.createChar(7, b4);
czas = millis();
temp1min = EEPROM.readFloat(1);
temp1max = EEPROM.readFloat(10);
temp2min = EEPROM.readFloat(20);
temp2max = EEPROM.readFloat(30);
temp3min = EEPROM.readFloat(40);
temp3max = EEPROM.readFloat(50);
}
void loop() {
if ((millis()-czas) > 1000){ czas = millis(); klawsek = klawsek + 1; };
// ODCZYT Z A1 I USTALENIE KLAWISZA /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
kwart = analogRead(A1);
if (kwart > 1000 ) {klaw = 4;delay(200);}else
if (kwart > 500 & kwart < 520 ){klaw = 3;delay(200);}else
if (kwart > 330 & kwart < 350 ){klaw = 2;delay(200);}else
if (kwart > 240 & kwart < 270 ){klaw = 1;delay(200);} else {klaw = 0;};
if (klaw > 0) {klawsek = 0;};
if (klawsek > 2000){klawsek = 100;};
if (klawsek > 15){menuin = 0;};
// STEROWANIE MENU //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (menuin == 0 && klaw == 1){menuin = 1; menu = 0;klaw = 0;lcd.clear();lcd.setCursor(0, 0); lcd.print(F("Menu"));lcd.setCursor(0, 1); lcd.print(F("Ustawien"));delay(1000);}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (menuin == 0 && klaw == 2 && al1 == 0){al1=1;klaw = 0;} else if (menuin == 0 && klaw == 2 && al1 == 1){al1=0;}
if (menuin == 0 && klaw == 3 && al2 == 0){al2=1;klaw = 0;} else if (menuin == 0 && klaw == 3 && al2 == 1){al2=0;}
if (menuin == 0 && klaw == 4 && al3 == 0){al3=1;klaw = 0;} else if (menuin == 0 && klaw == 4 && al3 == 1){al3=0;}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (menuin == 0 && al1==1) {
if (temp1min > 0 && temp1min >= temp1) {al1min = 1;} else {al1min = 0;};
if (temp1max > 0 && temp1max <= temp1) {al1max = 1;} else {al1max = 0;};
if (al1min == 1 || al1max == 1) {al1stan = 1;} else {al1stan = 0;};
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (menuin == 0 && al2==1) {
if (temp2min > 0 && temp2min >= temp2) {al2min = 1;} else {al2min = 0;};
if (temp2max > 0 && temp2max <= temp2) {al2max = 1;} else {al2max = 0;};
if (al2min == 1 || al2max == 1) {al2stan = 1;} else {al2stan = 0;};
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (menuin == 0 && al3==1) {
if (temp3min > 0 && temp3min >= temp3) {al3min = 1;} else {al3min = 0;};
if (temp3max > 0 && temp3max <= temp3) {al3max = 1;} else {al3max = 0;};
if (al3min == 1 || al3max == 1) {al3stan = 1;} else {al3stan = 0;};
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (menuin == 1){
if (klaw == 0){delay(100); ;}
lcd.clear();
if (klaw == 1 && menu < 9){menuin = 0;lcd.clear();menu = 0;}
if (klaw == 2 && menu < 99){menu = menu-1;}
if (klaw == 3 && menu < 99){menu = menu+1;}
if (klaw == 4 && menu < 99 ){menu = menu*10;klaw = 0;}
if (klaw == 1 && menu > 9){menu = menu/10;}
if (klaw == 1 && menu > 99){menu = menu/10;}
if (klaw == 2 && menu > 99){val = val - 0.1;}
if (klaw == 3 && menu > 99){val = val + 0.1;}
val=constrain(val,0,120);
switch (menu) {
case 0:
menu=1;
break;
case 1:
lcd.setCursor(0, 0); lcd.print(F("1. Ustaw. Al."));
lcd.setCursor(0, 1); lcd.print(F("Termometr 1"));
break;
case 9:
menu = 10;
break;
case 10:
lcd.setCursor(0, 0); lcd.print(F("1.1 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Min [ ] "));
lcd.setCursor(9, 1); lcd.print(temp1min,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 100:
val = temp1min;
menu = 101;
klaw = 0;
break;
case 101:
if (klaw == 4 && menu > 99){temp1min = val;menu = menu/10; EEPROM.writeFloat(1,val);}
lcd.setCursor(0, 0); lcd.print(F("1.1 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Min > < "));
lcd.setCursor(9, 1); lcd.print(val,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 11:
lcd.setCursor(0, 0); lcd.print(F("1.2 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Max [ ] "));
lcd.setCursor(9, 1); lcd.print(temp1max,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 110:
val = temp1max;
menu = 111;
klaw = 0;
break;
case 111:
if (klaw == 4 && menu > 99){temp1max = val;menu = menu/10;EEPROM.writeFloat(10,val);}
lcd.setCursor(0, 0); lcd.print(F("1.2 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Max > < "));
lcd.setCursor(9, 1); lcd.print(val,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 12:
menu = 11;
break;
case 2:
lcd.setCursor(0, 0); lcd.print(F("2. Ustaw. AL."));
lcd.setCursor(0, 1); lcd.print(F("Termometr 2"));
break;
case 19:
menu = 20;
break;
case 20:
lcd.setCursor(0, 0); lcd.print(F("2.1 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Min [ ] "));
lcd.setCursor(9, 1); lcd.print(temp2min,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 200:
val = temp2min;
menu = 201;
klaw = 0;
break;
case 201:
if (klaw == 4 && menu > 99){temp2min = val;menu = menu/10;EEPROM.writeFloat(20,val);}
lcd.setCursor(0, 0); lcd.print(F("2.1 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Min > < "));
lcd.setCursor(9, 1); lcd.print(val,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 21:
lcd.setCursor(0, 0); lcd.print(F("2.2 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Max [ ] "));
lcd.setCursor(9, 1); lcd.print(temp2max,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 210:
val = temp2max;
menu = 211;
klaw = 0;
break;
case 211:
if (klaw == 4 && menu > 99){temp2max = val;menu = menu/10;EEPROM.writeFloat(30,val);}
lcd.setCursor(0, 0); lcd.print(F("2.2 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Max > < "));
lcd.setCursor(9, 1); lcd.print(val,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 22:
menu = 21;
break;
case 3:
lcd.setCursor(0, 0); lcd.print(F("3. Ustaw. AL."));
lcd.setCursor(0, 1); lcd.print(F("Termometr 3"));
break;
case 29:
menu = 30;
break;
case 30:
lcd.setCursor(0, 0); lcd.print(F("3.1 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Min [ ] "));
lcd.setCursor(9, 1); lcd.print(temp3min,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 300:
val = temp3min;
menu = 301;
klaw = 0;
break;
case 301:
if (klaw == 4 && menu > 99){temp3min = val;menu = menu/10;EEPROM.writeFloat(40,val);}
lcd.setCursor(0, 0); lcd.print(F("3.1 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Min > < "));
lcd.setCursor(9, 1); lcd.print(val,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 31:
lcd.setCursor(0, 0); lcd.print(F("3.2 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Max [ ] "));
lcd.setCursor(9, 1); lcd.print(temp3max,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 310:
val = temp3max;
menu = 311;
klaw = 0;
break;
case 311:
if (klaw == 4 && menu > 99){temp3max = val;menu = menu/10;EEPROM.writeFloat(50,val);}
lcd.setCursor(0, 0); lcd.print(F("3.2 Ustaw. Alarmu."));
lcd.setCursor(0, 1); lcd.print(F("Max > < "));
lcd.setCursor(9, 1); lcd.print(val,1);
lcd.setCursor(15, 1); lcd.write(byte(1));
break;
case 32:
menu = 31;
break;
case 4:
menu=3;
break;
}}
if (menuin == 0){
delay(100);
lcd.clear();
//lcd.setCursor(8, 1); lcd.write(byte(5));
if (temp1 > 99) {lcd.setCursor(1, 0);} else {lcd.setCursor(2, 0);}
lcd.print(temp1,1);
lcd.setCursor(6, 0);
lcd.write(byte(1));
if (temp2 > 99) {lcd.setCursor(10, 0);} else {lcd.setCursor(11, 0);}
lcd.print(temp2,1);
lcd.setCursor(15, 0);
lcd.write(byte(1));
if (temp3 > 99) {lcd.setCursor(1, 1);} else {lcd.setCursor(2, 1);}
lcd.print(temp3,1);
lcd.setCursor(6, 1);
lcd.write(byte(1));
//lcd.setCursor(12, 1);
//lcd.print(klawsek);
dzwiek = 0;
if (al1stan == 0 && al1==1) {lcd.setCursor(0, 0);lcd.write(byte(3));};
if (al1stan == 1 && al1==1) {lcd.setCursor(0, 0);lcd.write(byte(2));dzwiek = 1;};
if (al2stan == 0 && al2==1) {lcd.setCursor(9, 0);lcd.write(byte(3));};
if (al2stan == 1 && al2==1) {lcd.setCursor(9, 0);lcd.write(byte(2));dzwiek = 1;};
if (al3stan == 0 && al3==1) {lcd.setCursor(0, 1);lcd.write(byte(3));};
if (al3stan == 1 && al3==1) {lcd.setCursor(0, 1);lcd.write(byte(2));dzwiek = 1;};
if (millis() - previousMillis > 1000)
{
temp1 = sensors.getTempC(czuj1);
temp2 = sensors.getTempC(czuj2);
temp3 = sensors.getTempC(czuj3);
sensors.setWaitForConversion(false);
sensors.requestTemperatures();
previousMillis = millis();
}
}
if (dzwiek == 1) { if (ton==0){ton=1;tone(10,2000);} else if (ton==1){ton=0;tone(10,1000);};} else {noTone(10);}
wdt_reset();
}
Kod: Zaznacz cały
if (millis() - previousMillis > 1000)
{
temp1 = sensors.getTempC(czuj1);
temp2 = sensors.getTempC(czuj2);
temp3 = sensors.getTempC(czuj3);
sensors.setWaitForConversion(false);
sensors.requestTemperatures();
previousMillis = millis();
}