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. General Discussion
  3. Less Optimised Code for Beginners PLEASE?

Less Optimised Code for Beginners PLEASE?

Scheduled Pinned Locked Moved General Discussion
2 Posts 2 Posters 1.0k Views 1 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.
  • B Offline
    B Offline
    bluman
    wrote on last edited by
    #1

    Hi there,

    Thanks to Hek, I've been having a great time with My Sensors for a while. I've just got back into it after about a 12 month break and upgrading various sensors from 1.3 to 1.4.

    I'm struggling with the new 1.4 code as the examples under the Build section use some very nice code which helps optimise the sketch size.
    This optimisation makes it more difficult to clearly understand what is happening for "beginner coders" like myself.

    I use the function incomingMessage from the relay sketch below as an example. It contains a line of code to change the relay status as commented.

     // Change relay state
     digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
    

    Trying to adapt this to work with ones own variables can be very confusing.

    Could someone please expand this out to show such code more clearly for beginners?
    It might make it easier if the expanded version of this line is shown as a comment in the code?

    This basic approach for the Build examples may help others overcome similar issues and increase the adoption of My Sensors in general.

    Regards
    Bluman

    O 1 Reply Last reply
    1
    • B bluman

      Hi there,

      Thanks to Hek, I've been having a great time with My Sensors for a while. I've just got back into it after about a 12 month break and upgrading various sensors from 1.3 to 1.4.

      I'm struggling with the new 1.4 code as the examples under the Build section use some very nice code which helps optimise the sketch size.
      This optimisation makes it more difficult to clearly understand what is happening for "beginner coders" like myself.

      I use the function incomingMessage from the relay sketch below as an example. It contains a line of code to change the relay status as commented.

       // Change relay state
       digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
      

      Trying to adapt this to work with ones own variables can be very confusing.

      Could someone please expand this out to show such code more clearly for beginners?
      It might make it easier if the expanded version of this line is shown as a comment in the code?

      This basic approach for the Build examples may help others overcome similar issues and increase the adoption of My Sensors in general.

      Regards
      Bluman

      O Offline
      O Offline
      olaeke
      wrote on last edited by
      #2

      @bluman
      If it is the ? operator that is the fuzzy one then you can rewrite the statement like:

      if (message.getBool())
        digitalWrite(message.sensor-1+RELAY_1, true);
      else
        digitalWrite(message.sensor-1+RELAY_1, false);
      

      The ? operator act like: expression?truepart:falsepart
      So if expression is true the it executes the truepart else it executes the falsepart

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


      22

      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