Hello, all. Was involved 2 years ago with arduino coding and managed to draft something that was running. It was a basic I2C, Temp and RTC. Now I want to expand the code with PWM LED control but something is strange with the code.
There is the code:
---#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
int DS18S20_Pin = 2;
OneWire ds(DS18S20_Pin);
LiquidCrystal_I2C lcd(0x3F, 20, 4);
void setup(void) {
lcd.begin(20, 4);
lcd.backlight();
lcd.init();
Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
}
void loop(void)
{
digitalClockDisplay();
delay(1000);
}
{
float temperature = getTemp();
Serial.println(temperature);
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.setCursor(5,0);
lcd.print(temperature);
lcd.setCursor(10, 0);
lcd.print((char)223);
lcd.setCursor(11, 0);
lcd.print("C");
delay(1000);
}
float getTemp(){
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
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;
}
void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
lcd.setCursor(0, 0); // Set LCD cursor position (column, row)
lcd.print(hour());
lcd.print(":");
lcd.print (minute());
lcd.print(":");
lcd.print(second());
// Print text to LCD
// Delay to read text
// Clear the display
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
--- End code ---
Nice. The link from the first answer helped me, but still receiving the same error on line 32. :)
DrAzzy:
--- Code: ---void loop(void)
{
digitalClockDisplay();
delay(1000);
} //here's the
{ //problem
float temperature = getTemp();
Serial.println(temperature);
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.setCursor(5,0);
lcd.print(temperature);
lcd.setCursor(10, 0);
lcd.print((char)223);
lcd.setCursor(11, 0);
lcd.print("C");
delay(1000);
}
Why I'm receiving an error on: lcd.int()?
Has something changed?
Thank you in advance for the cooperation