Pages: 1 [2]   Go Down
Author Topic: Runing small program in main loop - timealarm  (Read 2350 times)
0 Members and 1 Guest are viewing this topic.
New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Slovakia
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks wildbill,
I took it out:
Code:
#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
#define TEMPERATURE_PRECISION 12

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()
{   
  Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway, subnet );
  server.begin();
 
//******************************************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.begin();
  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);
  }
           digitalClockDisplay();
           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:
           digitalClockDisplay();
           Alarm.delay(1000); // wait one second between clock display
It says:
Code:
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
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The compiler is complaining that these two lines:
Code:
          digitalClockDisplay();
           Alarm.delay(1000); // wait one second between clock display

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

Pages: 1 [2]   Go Up
Jump to: