Go Down

Topic: Runing small program in main loop - timealarm (Read 4415 times) previous topic - next topic


You have declared those functions inside the loop function. C++ does not permit nested functions - move them outside loop, like your getTemperature function. Mind you, since they only consist of a single statement each, you might just get rid of the functions and leave the digitalwrite statements that they contain.


Thanks wildbill,
I took it out:
Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <RCSwitch.h>
#include <Time.h>
#include <TimeAlarms.h>

#define ONE_WIRE_BUS 3

float tempC;

OneWire oneWire(ONE_WIRE_BUS);         // setup a onewire instance to communicate with any onewire devices
DallasTemperature sensors(&oneWire);   // pass onewire reference to Dallas Temperature
RCSwitch mySwitch = RCSwitch();

DeviceAddress TN = { 0x28, 0x44, 0x33, 0x9D, 0x01, 0x00, 0x00, 0xAA };
DeviceAddress TO = { 0x28, 0x49, 0x45, 0x9D, 0x01, 0x00, 0x00, 0x11 };
DeviceAddress TP = { 0x28, 0xAE, 0x2E, 0x9D, 0x01, 0x00, 0x00, 0xDC };
DeviceAddress TV = { 0x28, 0xB7, 0x22, 0x9D, 0x01, 0x00, 0x00, 0x30 };
DeviceAddress TOUT = { 0x28, 0x3E, 0x3B, 0x9D, 0x01, 0x00, 0x00, 0xC3 };

byte    mac[] =     { 0x90, 0xA2, 0xDA, 0x00, 0x8D, 0x42 };   
byte    ip[] =      { 192, 168, 1, 104 };                     
byte    gateway[] = { 192, 168, 1, 1 };                       
byte    subnet[] =  { 255, 255, 255, 0 };                                 
EthernetServer  server(80);         
int     vedpin = 5;                // ventilation pin
int     heatpin = 6;               // heating pin
int     prdpin = 7;                // program/mode pin
int     gatepin = 8;               // gate opener pin                             
int     sensorPin = A0;            // light sensing analog
int     sensorValue = 0;           // integer for the analog sensor
int     PIRstate = 0;              // variable for PIR sensor status
int     llight = 9;
int     PIR = 14;                   // PIR
int     motorlevel = 0;            // motor
String  readString = String(30);   // string for fetching data from address
boolean GADON = false;             // status flag gate
boolean HEDON = false;             // status flag heating 
boolean PRDON = false;             // status flag ventilation program
boolean VEDON = false;             // status flag ventilation
boolean LLIGHT = false;            // status flag livingroom ligh

void setup()
  Ethernet.begin(mac, ip, gateway, subnet );
//******************************************time and alarm set********************************************
  setTime(18,00,00,3,7,13);    // time from arduino
  Alarm.alarmRepeat(6,30,00, M1 );       
  Alarm.alarmRepeat(7,30,05, M2 );       
  Alarm.alarmRepeat(8,30,10, D1 );       
  Alarm.alarmRepeat(9,30,15, D2 );       
  Alarm.alarmRepeat(14,30,20, D3 ); 
  mySwitch.enableTransmit(9);                   // transmitter is connected to arduino Pin #9
  mySwitch.setPulseLength(360);                 // pulse length
  pinMode(gatepin, OUTPUT);
  pinMode(heatpin, OUTPUT);
  pinMode(prdpin, OUTPUT);
  pinMode(vedpin, OUTPUT);
  pinMode(llight, OUTPUT);
  pinMode(PIR, INPUT);
  //tu bolo  byte client_ip[4];   
  sensors.setResolution(TN, TEMPERATURE_PRECISION);
  sensors.setResolution(TO, TEMPERATURE_PRECISION);
  sensors.setResolution(TP, TEMPERATURE_PRECISION);
  sensors.setResolution(TV, TEMPERATURE_PRECISION);
  sensors.setResolution(TOUT, TEMPERATURE_PRECISION);
   void getTemperature(DeviceAddress deviceAddress)   // function to get the temperature for a device
  tempC = sensors.getTempC(deviceAddress);
  sensorValue = analogRead(sensorPin);
           Alarm.delay(1000); // wait one second between clock display
          void M1(){
          digitalWrite (vedpin,HIGH);
          void M2(){
          digitalWrite (vedpin,LOW);
          void D1(){
          digitalWrite (vedpin,HIGH);
          void D2(){
          digitalWrite (vedpin,LOW);
          void D3(){
          digitalWrite (vedpin,LOW);

but I still have some error at lines:
Code: [Select]
           Alarm.delay(1000); // wait one second between clock display

It says:
Code: [Select]
Workingcode6m13:91: error: expected constructor, destructor, or type conversion before ';' token
Workingcode6m13:92: error: expected constructor, destructor, or type conversion before '.' token
Workingcode6m13:93: error: expected declaration before '}' token


The compiler is complaining that these two lines:
Code: [Select]

           Alarm.delay(1000); // wait one second between clock display

Are not in a function. The closing brace after them is likely annoying it too.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131