Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Binary switch project

Binary switch project

Scheduled Pinned Locked Moved Troubleshooting
3 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mikeg291M Offline
    mikeg291M Offline
    mikeg291
    wrote on last edited by mfalkvidd
    #1

    I cannot figure out how to correct the errors that I am getting. on this project. I need help

    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    #include <Time.h>
    
    #define CHILD_ID 3
    #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
    int alarmtime = 15;
    MySensor gw;
    Bounce debouncer = Bounce(); 
    int oldValue=-1;
    
    time_t  lastSwitchTime = 0;
    void receiveTime(unsigned long controllerTime);
    bool timeReceived = false;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID,V_TRIPPED);
    
    void setup()  
    {  
      gw.begin();
      // Serial.begin(9600);
     // Setup the button
      pinMode(BUTTON_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
      
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
      
      // Register binary input sensor to gw (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
       gw.present(CHILD_ID, S_DOOR);  
      
      // Make sure we get the system time, repeat request every 5 seconds until we have a valid time
      gw.requestTime(receiveTime);
      unsigned long lastRequest = millis();
      if ((millis() - lastRequest) >  5000) {
          gw.wait(100);
          gw.requestTime(receiveTime); 
          lastRequest = millis();
       }
       lastSwitchTime = now();
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop() 
    {
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
     
      if (value != oldValue) {
         Serial.print("Switch was ");
         Serial.print(oldValue ? "ON" : "OFF");
         Serial.print(" for: ");
         Serial.print(now() - lastSwitchTime);
         Serial.println(" seconds");
         lastSwitchTime = now();
         
         // Send in the new value 
        if (value < == alarmtime );
         gw.send(msg.set(value==HIGH 1));
         else 
         gw.send(msg.set(value=LOW 0));
         oldValue = value;
    
      }
    } 
    
    // This is called when a new time value was received
    void receiveTime(unsigned long controllerTime) {
       // OK, set incoming time
       Serial.print(F("Time value received: "));
       Serial.println(controllerTime);
       setTime(controllerTime); 
       timeReceived = true;
    }
    

    Arduino: 1.6.7 (Windows 7), Board: "Arduino Nano, ATmega328"

    C:\Users\repair\Documents\Arduino\pump_cycle_time_2.5\pump_cycle_time_2.5.ino: In function 'void loop()':

    pump_cycle_time_2.5:66: error: expected primary-expression before '==' token

     if (value < == alarmtime );
    
                 ^
    

    pump_cycle_time_2.5:67: error: expected ')' before numeric constant

      gw.send(msg.set(value==HIGH 1));
    
                                  ^
    

    pump_cycle_time_2.5:68: error: expected '}' before 'else'

      else 
    
      ^
    

    pump_cycle_time_2.5:69: error: expected ')' before numeric constant

      gw.send(msg.set(value=LOW 0));
    
                                ^
    

    C:\Users\repair\Documents\Arduino\pump_cycle_time_2.5\pump_cycle_time_2.5.ino: At global scope:

    pump_cycle_time_2.5:73: error: expected declaration before '}' token

    }

    ^

    C:\Users\repair\Documents\Arduino\pump_cycle_time_2.5\pump_cycle_time_2.5.ino: In function 'void loop()':

    pump_cycle_time_2.5:66: error: expected primary-expression before '==' token

     if (value < == alarmtime );
    
                 ^
    

    pump_cycle_time_2.5:67: error: expected ')' before numeric constant

      gw.send(msg.set(value==HIGH 1));
    
                                  ^
    

    pump_cycle_time_2.5:68: error: expected '}' before 'else'

      else 
    
      ^
    

    pump_cycle_time_2.5:69: error: expected ')' before numeric constant

      gw.send(msg.set(value=LOW 0));
    
                                ^
    

    C:\Users\repair\Documents\Arduino\pump_cycle_time_2.5\pump_cycle_time_2.5.ino: At global scope:

    pump_cycle_time_2.5:73: error: expected declaration before '}' token

    }

    ^

    exit status 1
    exit status 1
    expected primary-expression before '==' token

    expected primary-expression before '==' token

    mfalkviddM 1 Reply Last reply
    0
    • mikeg291M mikeg291

      I cannot figure out how to correct the errors that I am getting. on this project. I need help

      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      #include <Time.h>
      
      #define CHILD_ID 3
      #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
      int alarmtime = 15;
      MySensor gw;
      Bounce debouncer = Bounce(); 
      int oldValue=-1;
      
      time_t  lastSwitchTime = 0;
      void receiveTime(unsigned long controllerTime);
      bool timeReceived = false;
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(CHILD_ID,V_TRIPPED);
      
      void setup()  
      {  
        gw.begin();
        // Serial.begin(9600);
       // Setup the button
        pinMode(BUTTON_PIN,INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN,HIGH);
        
        // After setting up the button, setup debouncer
        debouncer.attach(BUTTON_PIN);
        debouncer.interval(5);
        
        // Register binary input sensor to gw (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
         gw.present(CHILD_ID, S_DOOR);  
        
        // Make sure we get the system time, repeat request every 5 seconds until we have a valid time
        gw.requestTime(receiveTime);
        unsigned long lastRequest = millis();
        if ((millis() - lastRequest) >  5000) {
            gw.wait(100);
            gw.requestTime(receiveTime); 
            lastRequest = millis();
         }
         lastSwitchTime = now();
      }
      
      
      //  Check if digital input has changed and send in new value
      void loop() 
      {
        debouncer.update();
        // Get the update value
        int value = debouncer.read();
       
        if (value != oldValue) {
           Serial.print("Switch was ");
           Serial.print(oldValue ? "ON" : "OFF");
           Serial.print(" for: ");
           Serial.print(now() - lastSwitchTime);
           Serial.println(" seconds");
           lastSwitchTime = now();
           
           // Send in the new value 
          if (value < == alarmtime );
           gw.send(msg.set(value==HIGH 1));
           else 
           gw.send(msg.set(value=LOW 0));
           oldValue = value;
      
        }
      } 
      
      // This is called when a new time value was received
      void receiveTime(unsigned long controllerTime) {
         // OK, set incoming time
         Serial.print(F("Time value received: "));
         Serial.println(controllerTime);
         setTime(controllerTime); 
         timeReceived = true;
      }
      

      Arduino: 1.6.7 (Windows 7), Board: "Arduino Nano, ATmega328"

      C:\Users\repair\Documents\Arduino\pump_cycle_time_2.5\pump_cycle_time_2.5.ino: In function 'void loop()':

      pump_cycle_time_2.5:66: error: expected primary-expression before '==' token

       if (value < == alarmtime );
      
                   ^
      

      pump_cycle_time_2.5:67: error: expected ')' before numeric constant

        gw.send(msg.set(value==HIGH 1));
      
                                    ^
      

      pump_cycle_time_2.5:68: error: expected '}' before 'else'

        else 
      
        ^
      

      pump_cycle_time_2.5:69: error: expected ')' before numeric constant

        gw.send(msg.set(value=LOW 0));
      
                                  ^
      

      C:\Users\repair\Documents\Arduino\pump_cycle_time_2.5\pump_cycle_time_2.5.ino: At global scope:

      pump_cycle_time_2.5:73: error: expected declaration before '}' token

      }

      ^

      C:\Users\repair\Documents\Arduino\pump_cycle_time_2.5\pump_cycle_time_2.5.ino: In function 'void loop()':

      pump_cycle_time_2.5:66: error: expected primary-expression before '==' token

       if (value < == alarmtime );
      
                   ^
      

      pump_cycle_time_2.5:67: error: expected ')' before numeric constant

        gw.send(msg.set(value==HIGH 1));
      
                                    ^
      

      pump_cycle_time_2.5:68: error: expected '}' before 'else'

        else 
      
        ^
      

      pump_cycle_time_2.5:69: error: expected ')' before numeric constant

        gw.send(msg.set(value=LOW 0));
      
                                  ^
      

      C:\Users\repair\Documents\Arduino\pump_cycle_time_2.5\pump_cycle_time_2.5.ino: At global scope:

      pump_cycle_time_2.5:73: error: expected declaration before '}' token

      }

      ^

      exit status 1
      exit status 1
      expected primary-expression before '==' token

      expected primary-expression before '==' token

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by mfalkvidd
      #2

      pump_cycle_time_2.5:66: error: expected primary-expression before '==' token

       if (value < == alarmtime );
      

      pump_cycle_time_2.5:67: error: expected ')' before numeric constant

        gw.send(msg.set(value==HIGH 1));
      

      pump_cycle_time_2.5:68: error: expected '}' before 'else'
      pump_cycle_time_2.5:69: error: expected ')' before numeric constant

        gw.send(msg.set(value=LOW 0));
      

      Some things that should help:

      1. Press ctrl/cmd+T in the Arduino IDE. That will auto-format the code which will make it much easier to spot mistakes.
      2. In the forum, code is marked with three backticks, not [code]. I know it's a bit non-intuitive but it is just the way the forum is. I took the liberty to changre your [code] to backticks to make the post to make it more readable.
      3. Comparing if a value is smaller is done by <= in c/c++. But it looks like you are trying to compare the value (which is always 0 or 1) to 15. That seems a bit strange. Adding a comment explaining what you are trying to do should help others (and perhaps yourself on day) to figure out what you ate trying to accomplish.
      4. The code to run inside an if clause should be surrounded by { and }
      5. The if clause and the two gw.send can probably be replaced by a single
        gw.send(msg.set(value==HIGH?1:0));
      1 Reply Last reply
      0
      • mikeg291M Offline
        mikeg291M Offline
        mikeg291
        wrote on last edited by
        #3

        Sorry for the lack of clarity . I have used your tips to and update the sketch to no avail . What I am trying to do is use the switch to activate the time and use the time the switch was activated ( lastSwitchTime ) to compare to the (alarmTime ) and send the new (value ). ? . Once I resolve the current issues : I haven't gotten to it yet but , Once the alarmTime alarm is met I would like to have locked in requiring a reset are possible button push to clear it .
        [code]
        #include <MySensor.h>
        #include <SPI.h>
        #include <Bounce2.h>
        #include <Time.h>

        #define CHILD_ID 3
        #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
        int alarmTime = 15;
        MySensor gw;
        Bounce debouncer = Bounce();
        int oldValue = -1;

        time_t lastSwitchTime = 0;
        void receiveTime(unsigned long controllerTime);
        bool timeReceived = false;

        // Change to V_LIGHT if you use S_LIGHT in presentation below
        MyMessage msg(CHILD_ID, V_TRIPPED);

        void setup()
        {
        gw.begin();
        // Serial.begin(9600);
        // Setup the button
        pinMode(BUTTON_PIN, INPUT);
        // Activate internal pull-up
        digitalWrite(BUTTON_PIN, HIGH);

        // After setting up the button, setup debouncer
        debouncer.attach(BUTTON_PIN);
        debouncer.interval(5);

        // Register binary input sensor to gw (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        gw.present(CHILD_ID, S_DOOR);

        // Make sure we get the system time, repeat request every 5 seconds until we have a valid time
        gw.requestTime(receiveTime);
        unsigned long lastRequest = millis();
        if ((millis() - lastRequest) > 5000) {
        gw.wait(100);
        gw.requestTime(receiveTime);
        lastRequest = millis();
        }
        lastSwitchTime = now();
        }

        // Check if digital input has changed and send in new value
        void loop()
        {
        debouncer.update();
        // Get the update value
        int value = debouncer.read();

        if (value != oldValue) {
        Serial.print("Switch was ");
        Serial.print(oldValue ? "ON" : "OFF");
        Serial.print(" for: ");
        Serial.print(now() - lastSwitchTime);
        Serial.println(" seconds");
        lastSwitchTime = now();

        // Send in the new value
        if (alarmTime <= lastSwitchTime );
        

        { gw.send(msg.set(value == HIGH 1));}
        else
        { gw.send(msg.set(value = LOW 0));
        oldValue = value;

        }
        }

        // This is called when a new time value was received
        void receiveTime(unsigned long controllerTime) {
        // OK, set incoming time
        Serial.print(F("Time value received: "));
        Serial.println(controllerTime);
        setTime(controllerTime);
        timeReceived = true;
        }

        Arduino: 1.6.7 (Windows 7), Board: "Arduino Nano, ATmega328"

        C:\Users\repair\AppData\Local\Temp\arduino_9fa690567122ca1856b95eff67fbf9b8\pump_cycle_time_2.5.ino: In function 'void loop()':

        pump_cycle_time_2.5:67: error: expected ')' before numeric constant

        { gw.send(msg.set(value == HIGH 1));}
        
                                        ^
        

        pump_cycle_time_2.5:68: error: expected '}' before 'else'

         else
        
         ^
        

        pump_cycle_time_2.5:69: error: expected ')' before numeric constant

          { gw.send(msg.set(value = LOW 0));
        
                                        ^
        

        exit status 1
        expected ')' before numeric constant

        This report would have more information with
        "Show verbose output during compilation"
        enabled in File > Preferences.

        [/code]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        12

        Online

        11.7k

        Users

        11.2k

        Topics

        113.1k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular