ardujo
September 3, 2016, 12:24pm
1
Hi!
I want to get temperature data in a timer1-loop (void printtemperature()) and print it on an lcd-screen. In the void loop() I want to use this temperture to control a relais. The lcd-print works fine but I can't use the temperature variable (tempC) in the void loop(). I read that a void-loop cannot give back a variable. Is there way to do this anyway?
Thanks!
ardujo
void setup() {
pinMode(CH1, OUTPUT);
digitalWrite(CH1,LOW);
lcd.begin(16, 2);
lcd.print("Heizregler v1.0");
delay(3*1000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("IST");
lcd.setCursor(7, 0);
lcd.print("SOLL");
lcd.setCursor(13, 0);
lcd.print("MOD");
lcd.setCursor(13, 1);
lcd.print(modus_1);
lcd.setCursor(7, 1);
lcd.print(soll_temp,1);
sensors.begin();
sensors.setResolution(insideThermometer, 10);
Timer1.initialize(alle_x_sekunden*1000000);
Timer1.attachInterrupt(printTemperature);
}
//---------------------------------------------
void printTemperature()
{
sensors.requestTemperatures();
float tempC = sensors.getTempC(insideThermometer);
lcd.setCursor(1, 1);
if (tempC == -127.00) {
lcd.print("Err");
} else {
lcd.print(tempC);
}
ardujo
September 4, 2016, 9:42am
3
Thanks!!
I tried to use millis, but it there is an error and I don't find it....
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define CH1 12 // Connect Digital Pin 2 on Arduino to CH1 on Relay Module
#define ONE_WIRE_BUS 13
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer = { 0x28, 0xFF, 0x0C, 0xD6, 0x35, 0x16, 0x04, 0xAD };
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
String modus_1="AUS";
String modus_2="ANW";
int input_links_rechts;
float soll_temp = 29.5;
int readkey;
float tempC = 23;
int modus = 1;
unsigned long previousMillis = 0; // will store last time LED was updated
long Time_Temperature = 5000; // milliseconds of on-time
//--------------------------------------------
void setup() {
pinMode(CH1, OUTPUT);
digitalWrite(CH1,LOW);
lcd.begin(16, 2);
lcd.print("Heizregler v1.0");
delay(3*1000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("IST");
lcd.setCursor(7, 0);
lcd.print("SOLL");
lcd.setCursor(13, 0);
lcd.print("MOD");
lcd.setCursor(13, 1);
lcd.print(modus_1);
lcd.setCursor(7, 1);
lcd.print(soll_temp,1);
sensors.begin();
sensors.setResolution(insideThermometer, 10);
}
//---------------------------------------------
void loop() {
delay(300);
// int modus=modus;
readkey=analogRead(0); //buttons
if (readkey<50){
lcd.setCursor(13,1);
lcd.print("AUS");
modus = 0; //2 ->rechts
}
else if(readkey<195){ //->oben
if (input_links_rechts=2){
soll_temp=soll_temp+0.5;
lcd.setCursor(7, 1);
lcd.print(soll_temp, 1);
}}
else if(readkey<380){ //->unten
if (input_links_rechts=2){
soll_temp=soll_temp-0.5;
lcd.setCursor(7, 1);
lcd.print(soll_temp, 1);
}}
else if(readkey<790){
lcd.setCursor(13,1);
lcd.print("ANW");
modus = 1;
} //1->links
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= Time_Temperature)
{
previousMillis = currentMillis;
sensors.requestTemperatures();
float tempC = sensors.getTempC(insideThermometer);
lcd.setCursor(1, 1);
if (tempC == -127.00) {
lcd.print("Err");
}
else {
lcd.print(tempC);
}
}
if (modus == 1); //Regelung AN (Anwesend)
{
if (tempC < soll_temp-0.5)
{
lcd.setCursor(12,1);
lcd.print("*");
digitalWrite(CH1, LOW);
}
else if (tempC > soll_temp+0.5)
{
lcd.setCursor(12,1);
lcd.print("1");
digitalWrite(CH1, HIGH);
}
}
if (modus == 0); //Regelung AUS
{
digitalWrite(CH1, HIGH);
lcd.setCursor(12,1);
lcd.print("0");
}
}//loop ENDE
vaj4088
September 4, 2016, 3:42pm
4
If you want help you are going to have to be a lot more specific about what the error is.
I can tell you this:
The semicolon on the end of
if (modus == 0);
is probably going to get you into a lot of trouble.