Hello fellow Arduino fans.
I'm kinda new to the whole thing but have managed to get up and running quite quickly thanks to the awesome support.
I've come across a little niggle though and it's probably due to me being new to C (I'm a VB.NET programmer).
My question is this:
I'm trying to write Temperature (DS18B20) AND Time (DS1307) at the same time to the LCD but when I execute the command to get the temp, my time seems to stop running smoothly for just a second or 2 whilst the temp sensor is sending data.
I'm assuming it's a programming thing so I'd appreciate some pointers if you have any.
P.S. The switch is being de-bounced using a Schmitt Trigger so don't worry if "void swap()" looks a little too simple
The Sketch is as follows so far:
//LCD
// RS -> Arduino Digital 10
// E -> Arduino Digital 11
// DB4 -> Arduino Digital 6
// DB5 -> Arduino Digital 5
// DB6 -> Arduino Digital 4
// DB7 -> Arduino Digital 3
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Time.h>
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
//char* weekdayname[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
char* myDate;
char date[10];
char time[8];
#define ONE_WIRE_BUS 7 // Data wire is plugged into pin 7 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
LiquidCrystal lcd(10, 11, 6, 5, 4, 3); // initialize the library with the numbers of the interface pins
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature
const int ledPin = 13;
const int switchPin = 2;
volatile int lastButton = LOW;
unsigned long myTimer = millis();
void setup(void)
{
// Query the sensor
sensors.begin();
Wire.begin();
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(3,0);
lcd.print("Warming up");
delay(1000);
lcd.clear();
setTime(22,35,00,21,7,13); // (hr,min,sec,day,month,yr)
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
lcd.print(getTemperature());
lcd.print((char)223);
//Attatch the interrupt
attachInterrupt(0, swap, RISING);
}
void loop(void)
{
if (millis() - myTimer >= 30000){
// call sensors.requestTemperatures() to issue a global temperature request to all devices on the bus
//sensors.requestTemperatures();
lcd.setCursor(0,0);
lcd.print(getTemperature());
lcd.print((char)223);
myTimer = millis();
}
lcd.setCursor(0,1);
time_t t = now();
String stringTime = String(hour(t)) + ":" + String(minute(t)) + ":" + String(second(t));
lcd.print(stringTime);
}
//Function to toggle the LED/Relay from On to Off and vice versa
void swap()
{
if (digitalRead(switchPin) == HIGH && lastButton == LOW)
{
lastButton = HIGH;
}
else
{
lastButton = LOW;
}
digitalWrite(ledPin, lastButton);
}
//Function to return the Temperature from sensor
float getTemperature()
{
sensors.requestTemperatures();
return sensors.getTempCByIndex(0);
}
//Function to convert Binary Coded Decimal to Decimal
byte decToBcd(byte val)
{
return ((val/10*16) + (val%10));
}
//Function to convert Decimal to Binary Coded Decimal
byte bcdToDec(byte val)
{
return ((val/16*10) + (val%16));
}