Hi,
Can anybody tell me why does following message show up when I try to compile this sketch?
Sorry for my (bad) english :-)
"getTemp was not declared in this scope"
What can I do to fix it?
#include <OneWire.h>
#include <LiquidCrystal.h>
int DS18S20_Pin = 10;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//Temperature chip i/o
OneWire ds(DS18S20_Pin);
///////////////////////////////////
int val;
int Led = 13;
int reedswitch = 6;
byte PWM = 7;
byte DIR = 8;
byte setpoint = 23
;
///////////////////////////////////
void setup() {
Serial.begin(9600);
///////////////////////////////////
//pinMode(relay,OUTPUT);
pinMode (PWM,OUTPUT);
pinMode (DIR,OUTPUT);
pinMode (Led,OUTPUT);
pinMode (reedswitch,INPUT);
///////////////////////////////////
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(" ");
}
void loop() {
float temperature = getTemp();
Serial.println(temperature);
//////////////////////////////////
if(temperature >= setpoint)
digitalWrite(PWM,HIGH);// hög och låg kan vara tvärtom på andra board
else if(temperature <= setpoint -2)
digitalWrite(PWM,HIGH );
if(temperature >= setpoint )
digitalWrite(DIR,HIGH);
else if(temperature < setpoint -2)
digitalWrite(DIR,LOW);
val=digitalRead(reedswitch);
if(val==LOW)
digitalWrite(Led, HIGH);
}
}
//////////////////////////////////
lcd.setCursor(0, 1);
lcd.print("Temp : ");
lcd.print(temperature);
lcd.print(" *C");
delay(1000); //just here to slow down the output so it is easier to read
}
float getTemp(){
//returns the temperature from one DS18S20 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
delay(800); /////////////////
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 setpoint = 23
;
WTF? Why is the ; on a separate line?
If you put EVERY { on a line BY ITSELF, and EVERY } on a line BY ITSELF, and used Tools + Auto Format, it will become perfectly clear what the problem is.