Offline
Newbie
Karma: 0
Posts: 8
|
 |
« on: August 04, 2012, 02:16:37 pm » |
hi im all new to this and would be most appreciative if sombody could help with this code for a clock temperature its giving me the error msg
clock:108: error: expected unqualified-id before '{' token
heres the code
#include <OneWire.h> #include <DallasTemperature.h> #include <Wire.h> #define DS1307_I2C_ADDRESS 0x68 #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 8; #define ONE_WIRE_BUS 13
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); DeviceAddress insideThermometer = { 0x28, 0x2B, 0x12, 0x0D, 0x04, 0x00, 0x00, 0xAC};
byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); }
byte bcdToDec(byte val) { return ( (val/16*10) + (val%16) ); }
void setDateDs1307(byte second, byte minute, byte hour, byte dayOfWeek, byte dayMonth, byte month, byte year) { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(0); Wire.write(decToBcd(second)); Wire.write(decToBcd(minute)); Wire.write(decToBcd(hour)); Wire.write(decToBcd(dayOfWeek)); Wire.write(decToBcd(dayMonth)); Wire.write(decToBcd(month)); Wire.write(decToBcd(year)); Wire.write(0x10); Wire.endTransmission(); }
void getDateDs1307(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayMonth, byte *month, byte *year) {
Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
*second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); *dayOfWeek = bcdToDec(Wire.read()); *dayMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); } void setup() {
sensors.begin();
sensors.setResolution(insideThermometer, 10);
pinMode(backLight, OUTPUT); digitalWrite(backLight, HIGH); lcd.begin(16,2); lcd.clear(); }
void printTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); if (tempC == -127.00) { lcd.print("Error"); } else { lcd.print(tempC);
} }
{byte second, minute, hour, dayOfWeek, dayMonth, month, year; Wire.begin(); Serial.begin(9600); second = 0; minute = 42; hour = 9; dayOfWeek = 1; dayMonth = 3; month = 10; year = 10; lcd.begin(16, 2);
{ void loop()
delay(2000); sensors.requestTemperatures(); lcd.setCursor(0,0);
printTemperature(insideThermometer); lcd.print(char(223)); lcd.print('C'); } { byte second, minute, hour, dayOfWeek, dayMonth, month, year; getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayMonth, &month, &year); lcd.clear(); lcd.setCursor(7,0); lcd.print(" "); lcd.print(hour, DEC); lcd.print(":"); if (minute<10) { lcd.print("0"); } lcd.print(minute, DEC); lcd.print(":"); if (second<10) { lcd.print("0"); } lcd.print(second, DEC); lcd.setCursor(0,1); lcd.print(" "); switch(dayOfWeek){ case 7: lcd.print("Sun"); break; case 1: lcd.print("Mon"); break; case 2: lcd.print("Tue"); break; case 3: lcd.print("Wed"); break; case 4: lcd.print("Thu"); break; case 5: lcd.print("Fri"); break; case 6: lcd.print("Sat"); break; } lcd.print(" "); lcd.print(" "); lcd.print(dayMonth, DEC); lcd.print("/"); lcd.print(month, DEC); lcd.print("/20"); lcd.print(year, DEC); delay(1000); }
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3117
|
 |
« Reply #1 on: August 04, 2012, 02:42:34 pm » |
{ void loop() That doesn't look right. It also agrees with auto-format's 'too many left curly braces' message. I think that should be a closing brace instead. I recommend the use of auto-format - Ctrl-t/Cmd-t.
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
Edison Member
Karma: 38
Posts: 1029
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #2 on: August 04, 2012, 02:49:47 pm » |
The whole of this bit is just floating in the middle of nowhere and appears to serve no purpose. {byte second, minute, hour, dayOfWeek, dayMonth, month, year; Wire.begin(); Serial.begin(9600); second = 0; minute = 42; hour = 9; dayOfWeek = 1; dayMonth = 3; month = 10; year = 10; lcd.begin(16, 2);
{ The next bit is not quite right either. void loop()
delay(2000); sensors.requestTemperatures(); lcd.setCursor(0,0);
printTemperature(insideThermometer); lcd.print(char(223)); lcd.print('C'); } { Should be: [code]void loop(){
delay(2000); sensors.requestTemperatures(); lcd.setCursor(0,0);
printTemperature(insideThermometer); lcd.print(char(223)); lcd.print('C');
[/code]
|
|
|
|
« Last Edit: August 04, 2012, 02:52:01 pm by Tom Carpenter »
|
Logged
|
~Tom~
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #3 on: August 04, 2012, 03:09:44 pm » |
dont want to sound dumb but im confused ive never messed with code before
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #4 on: August 05, 2012, 09:13:03 am » |
any more input still stuck
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 336
Posts: 36486
Seattle, WA USA
|
 |
« Reply #5 on: August 05, 2012, 09:17:44 am » |
any more input still stuck "I made some code changes. I won't tell you what they were. I still need help" Perhaps, my rephrasing of your comment will help you see what you need to do.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #6 on: August 05, 2012, 09:45:46 am » |
changed a few bits but im not sure how this has affected its two codes combined getting these errors clock:17: error: expected unqualified-id before '[' token clock:109: error: expected unqualified-id before '{' token clock:128: error: expected unqualified-id before '[' token clock:138: error: expected unqualified-id before '{' token #include <OneWire.h> #include <DallasTemperature.h> #include <Wire.h> #define DS1307_I2C_ADDRESS 0x68 #include <LiquidCrystal.h> // we need this library for the LCD commands LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
#define ONE_WIRE_BUS 13 // Setup a oneWire instance to communicate with any OneWire devices OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); DeviceAddress insideThermometer = { 0x28, 0x2B, 0x12, 0x0D, 0x04, 0x00, 0x00, 0xAC};
// Convert normal decimal numbers to binary coded decimal byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); } // Convert binary coded decimal to normal decimal numbers byte bcdToDec(byte val) { return ( (val/16*10) + (val%16) ); } // 1) Sets the date and time on the ds1307 // 2) Starts the clock // 3) Sets hour mode to 24 hour clock // Assumes you're passing in valid numbers void setDateDs1307(byte second, // 0-59 byte minute, // 0-59 byte hour, // 1-23 byte dayOfWeek, // 1-7 byte dayOfMonth, // 1-28/29/30/31 byte month, // 1-12 byte year) // 0-99 { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(0); Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock Wire.write(decToBcd(minute)); Wire.write(decToBcd(hour)); Wire.write(decToBcd(dayOfWeek)); Wire.write(decToBcd(dayOfMonth)); Wire.write(decToBcd(month)); Wire.write(decToBcd(year)); Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave Wire.endTransmission(); } // Gets the date and time from the ds1307 void getDateDs1307(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year) { // Reset the register pointer Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 7); // A few of these need masks because certain bits are control bits *second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm *dayOfWeek = bcdToDec(Wire.read()); *dayOfMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); } void setup() { // Start up the library sensors.begin(); // set the resolution to 10 bit (good enough?) 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);
} }
{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; Wire.begin(); Serial.begin(9600); // Change these values to what you want to set your clock to. // You probably only want to set your clock once and then remove // the setDateDs1307 call. second = 0; minute = 42; hour = 9; dayOfWeek = 1; dayOfMonth = 3; month = 10; year = 10;
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); lcd.begin(16, 2); // tells Arduino the LCD dimensions
} [code]void loop(){
delay(2000); sensors.requestTemperatures(); lcd.setCursor(0,0);
printTemperature(insideThermometer); lcd.print(char(223)); lcd.print('C'); } { byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); lcd.clear(); // clear LCD screen lcd.setCursor(7,0); lcd.print(" "); lcd.print(hour, DEC); lcd.print(":"); if (minute<10) { lcd.print("0"); } lcd.print(minute, DEC); lcd.print(":"); if (second<10) { lcd.print("0"); } lcd.print(second, DEC); lcd.setCursor(0,1); lcd.print(" "); switch(dayOfWeek){ case 7: lcd.print("Sun"); break; case 1: lcd.print("Mon"); break; case 2: lcd.print("Tue"); break; case 3: lcd.print("Wed"); break; case 4: lcd.print("Thu"); break; case 5: lcd.print("Fri"); break; case 6: lcd.print("Sat"); break; } lcd.print(" "); lcd.print(" "); lcd.print(dayOfMonth, DEC); lcd.print("/"); lcd.print(month, DEC); lcd.print("/20"); lcd.print(year, DEC); delay(1000); } [/code]
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 100
Posts: 6787
-
|
 |
« Reply #7 on: August 05, 2012, 10:08:46 am » |
You seem to have posted two copies of your code so it's hard to know exactly what code you're running.
For goodness' sake, please indent your code. It's like wading through molasses trying to follow the structure of that. For extra brownie points, put each { and } on a separate line with each matching pair indented by the same amount - that style is not universally used but is the one that makes the structure of your code most obvious.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #8 on: August 05, 2012, 12:20:07 pm » |
the bottom set is the code im trying to use
ive never done any programming before hard to know where to start
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 336
Posts: 36486
Seattle, WA USA
|
 |
« Reply #9 on: August 05, 2012, 12:43:42 pm » |
hard to know where to start Start with following Peter's advice to put each { and } on it's own line. Then, use Tools + Auto Format to format the code. Then, post just the code you have questions about.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #10 on: August 05, 2012, 12:52:43 pm » |
whats meant by on its own line ?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 336
Posts: 36486
Seattle, WA USA
|
 |
« Reply #11 on: August 05, 2012, 12:59:46 pm » |
Each word in this reply is on its own line.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #12 on: August 05, 2012, 01:08:09 pm » |
gotcha  tidied up and auto formatted getting these errors now : clock:18: error: expected unqualified-id before '[' token clock:104: error: expected unqualified-id before '{' token clock:123: error: expected unqualified-id before '[' token clock:134: error: expected unqualified-id before '{' token #include <OneWire.h> #include <DallasTemperature.h> #include <Wire.h> #define DS1307_I2C_ADDRESS 0x68 #include <LiquidCrystal.h> #define ONE_WIRE_BUS 13 LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); DeviceAddress insideThermometer = { 0x28, 0x2B, 0x12, 0x0D, 0x04, 0x00, 0x00, 0xAC};
byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); } // Convert binary coded decimal to normal decimal numbers byte bcdToDec(byte val) { return ( (val/16*10) + (val%16) ); } // 1) Sets the date and time on the ds1307 // 2) Starts the clock // 3) Sets hour mode to 24 hour clock // Assumes you're passing in valid numbers void setDateDs1307(byte second, // 0-59 byte minute, // 0-59 byte hour, // 1-23 byte dayOfWeek, // 1-7 byte dayOfMonth, // 1-28/29/30/31 byte month, // 1-12 byte year) // 0-99 { Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(0); Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock Wire.write(decToBcd(minute)); Wire.write(decToBcd(hour)); Wire.write(decToBcd(dayOfWeek)); Wire.write(decToBcd(dayOfMonth)); Wire.write(decToBcd(month)); Wire.write(decToBcd(year)); Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave Wire.endTransmission(); } // Gets the date and time from the ds1307 void getDateDs1307(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year) { // Reset the register pointer Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 7); // A few of these need masks because certain bits are control bits *second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm *dayOfWeek = bcdToDec(Wire.read()); *dayOfMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); } void setup() { // Start up the library sensors.begin(); // set the resolution to 10 bit (good enough?) 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);
} }
{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; Wire.begin(); Serial.begin(9600); // Change these values to what you want to set your clock to. // You probably only want to set your clock once and then remove // the setDateDs1307 call. second = 0; minute = 42; hour = 9; dayOfWeek = 1; dayOfMonth = 3; month = 10; year = 10;
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); lcd.begin(16, 2); // tells Arduino the LCD dimensions
} [code]void loop() {
delay(2000); sensors.requestTemperatures(); lcd.setCursor(0,0);
printTemperature(insideThermometer); lcd.print(char(223)); lcd.print('C'); } { byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); lcd.clear(); // clear LCD screen lcd.setCursor(7,0); lcd.print(" "); lcd.print(hour, DEC); lcd.print(":"); if (minute<10) { lcd.print("0"); } lcd.print(minute, DEC); lcd.print(":"); if (second<10) { lcd.print("0"); } lcd.print(second, DEC); lcd.setCursor(0,1); lcd.print(" "); switch(dayOfWeek){ case 7: lcd.print("Sun"); break; case 1: lcd.print("Mon"); break; case 2: lcd.print("Tue"); break; case 3: lcd.print("Wed"); break; case 4: lcd.print("Thu"); break; case 5: lcd.print("Fri"); break; case 6: lcd.print("Sat"); break; } lcd.print(" "); lcd.print(" "); lcd.print(dayOfMonth, DEC); lcd.print("/"); lcd.print(month, DEC); lcd.print("/20"); lcd.print(year, DEC); delay(1000); }
[/code]
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
Edison Member
Karma: 38
Posts: 1029
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #13 on: August 05, 2012, 01:28:58 pm » |
[code]void loop() //Woops, somebody left a [code] tag behind, you need to remove that! {
delay(2000); sensors.requestTemperatures(); lcd.setCursor(0,0);
printTemperature(insideThermometer); lcd.print(char(223)); lcd.print('C'); }//These two brackets aren't needed as the next bit is part of loop() { ... [/code][/code]
|
|
|
|
|
Logged
|
~Tom~
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 25
Posts: 748
|
 |
« Reply #14 on: August 05, 2012, 01:48:34 pm » |
Look for comments "MISSING FUNCTION NAME" #include <OneWire.h> #include <DallasTemperature.h> #include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#include <LiquidCrystal.h>
#define ONE_WIRE_BUS 13
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); DeviceAddress insideThermometer = { 0x28, 0x2B, 0x12, 0x0D, 0x04, 0x00, 0x00, 0xAC };
byte decToBcd(byte val) { return ((val / 10 * 16) + (val % 10)); }
// Convert binary coded decimal to normal decimal numbers byte bcdToDec(byte val) { return ((val / 16 * 10) + (val % 16)); }
// 1) Sets the date and time on the ds1307 // 2) Starts the clock // 3) Sets hour mode to 24 hour clock // Assumes you're passing in valid numbers
void setDateDs1307( byte second, // 0-59 byte minute, // 0-59 byte hour, // 1-23 byte dayOfWeek, // 1-7 byte dayOfMonth, // 1-28/29/30/31 byte month, // 1-12 byte year) // 0-99 { Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0); Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock Wire.write(decToBcd(minute)); Wire.write(decToBcd(hour)); Wire.write(decToBcd(dayOfWeek)); Wire.write(decToBcd(dayOfMonth)); Wire.write(decToBcd(month)); Wire.write(decToBcd(year)); Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission(); }
// Gets the date and time from the ds1307
void getDateDs1307( byte* second, byte* minute, byte* hour, byte* dayOfWeek, byte* dayOfMonth, byte* month, byte* year) { // Reset the register pointer Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits *second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm *dayOfWeek = bcdToDec(Wire.read()); *dayOfMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); }
void setup() { // Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
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); } }
// MISSING FUNCTION NAME
{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin(); Serial.begin(9600);
// Change these values to what you want to set your clock to. // You probably only want to set your clock once and then remove // the setDateDs1307 call.
second = 0; minute = 42; hour = 9; dayOfWeek = 1; dayOfMonth = 3; month = 10; year = 10;
// setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); lcd.begin(16, 2); // tells Arduino the LCD dimensions }
void loop() { delay(2000); sensors.requestTemperatures(); lcd.setCursor(0,0);
printTemperature(insideThermometer); lcd.print(char(223)); lcd.print('C'); }
// MISSING FUNCTION NAME
{ byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.clear(); // clear LCD screen
lcd.setCursor(7,0); lcd.print(" ");
lcd.print(hour, DEC);
lcd.print(":");
if (minute < 10) { lcd.print("0"); } lcd.print(minute, DEC);
lcd.print(":");
if (second < 10) { lcd.print("0"); } lcd.print(second, DEC);
lcd.setCursor(0,1); lcd.print(" ");
switch(dayOfWeek) { case 7: lcd.print("Sun"); break; case 1: lcd.print("Mon"); break; case 2: lcd.print("Tue"); break; case 3: lcd.print("Wed"); break; case 4: lcd.print("Thu"); break; case 5: lcd.print("Fri"); break; case 6: lcd.print("Sat"); break; }
lcd.print(" "); lcd.print(" "); lcd.print(dayOfMonth, DEC); lcd.print("/"); lcd.print(month, DEC); lcd.print("/20"); lcd.print(year, DEC);
delay(1000); }
|
|
|
|
« Last Edit: August 05, 2012, 02:52:12 pm by lloyddean »
|
Logged
|
|
|
|
|
|