Go Down

Topic: LCD shield menu (Read 2 times) previous topic - next topic

karlok

Yes, this is the same idea as above.
I just suggested a solution that uses this linear correlation I mentioned. How to finally implement the feature is left to the author.
using Arduino Uno Rev 3

employer

Hello, I am sorry for my absence.
Thanks everyone for help with menu.
I need this menu to bulid  steering of kettle. I want to measure temperature and activate pump. I try to do this in code below. I use sensor DS18B20 and LED on pin 52. In egz wen temp is over 25deg pin 52 is high. I cant place this part of code to void loop because is generate error: tempC is not declared in this scope. When I place it into void setup is working good.
What I do wrong?

Thank you for help.


code:
   
Code: [Select]
if (tempC >= 25.00)
    {
     digitalWrite(52, HIGH);
    }
    else
    {
      digitalWrite(52, LOW);
    }



code:
Code: [Select]
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #include <LiquidCrystal.h>
    #define ONE_WIRE_BUS 22

    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    DeviceAddress insideThermometer = { 0x28, 0x26, 0x44, 0xBB, 0x03, 0x00, 0x00, 0x0D };




    void setup(void)
    {
      Serial.begin(9600);
      pinMode(52, OUTPUT);
      sensors.begin();
      sensors.setResolution(insideThermometer, 10);
      lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
      lcd.clear(); // start with a blank screen
    }
      void printTemperature(DeviceAddress deviceAddress)
    {
      float tempC = sensors.getTempC(deviceAddress);
      if (tempC == -127.00) {
      lcd.print("Error");
    }
      else {
      lcd.print(tempC);
    }
    }


    void loop(void)
    {
      delay(2000);
      sensors.requestTemperatures();
      lcd.setCursor(0,0);
      lcd.print("kociol: ");
      printTemperature(insideThermometer);
      lcd.write(0xDF);
      lcd.write('C');
    }







karlok

I don't see a "tempC" in your loop.
You could also initiate  (e.g. declare)  this var at the very beginning after havign defined the classes instances 
using Arduino Uno Rev 3

employer

You don't see tempC in loop because when i declare:
float tempC;
   if (tempC >= 25.00)
    {
     digitalWrite(52, HIGH);
    }
    else
    {
      digitalWrite(52, LOW);
    }
and I print tempC on serial i recive value: 0.00
On lcd I have good temperature.

PaulS

Quote
You don't see tempC in loop because when i declare:
float tempC;
   if (tempC >= 25.00)
    {
     digitalWrite(52, HIGH);
    }
    else
    {
      digitalWrite(52, LOW);
    }
and I print tempC on serial i recive value: 0.00

When I declare a variable, but don't give it a value, I get zero. Why is that?

Go Up