custom pin control for my solar water heater

Discussions related to network, internet and socket programming; also to serial, parallel, Bluetooth, USB etc.
mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

custom pin control for my solar water heater

Post by mikeg »

I was quick to customize the pin control information for my solar water heater (ok I could have been a lot faster)
I tested this sample and it works. I now will make the video showing the relay running the water heater in action.
And many thanks to Richard Russell for helping me understand how to do this.

Code: Select all

 REM Initialise GPIO:
      INSTALL @lib$ + "gpiolib"
      GPIO% = FN_gpio_setup
      REM custom command for 1 pin use (I will make a mass pin tool later)
      PROC_pinprep(24):REM assumes that you are just using 1 pin(GPIO 24
      PROC_pin(24,"ON"):REM turn on pin 24 for relay
      WAIT 20:REM lets assume that my water takes this long to heat
      PROC_pin(24,"OFF"):REM turn off pin 24
      END
      REM lets make it custom
      REM so for example PROCpin(24,"ON") or PROCpin(24,"OFF")
      DEF PROC_pin(pin%,onoff$)
      IF onoff$="ON" THEN PROC_gpio_set(GPIO%, 1 << pin%)
      IF onoff$="OFF" THEN PROC_gpio_clr(GPIO%, 1 << pin%)
      ENDPROC
      REM made this to do the required pin input/output cycle
      DEFPROC_pinprep(pin%)
      PROC_gpio_inp(GPIO%, pin%)
      PROC_gpio_out(GPIO%, pin%)
      ENDPROC
Focus is on code subject. Feel free to judge the quality of my work.
User avatar
hellomike
Posts: 184
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: custom pin control for my solar water heater

Post by hellomike »

Nice little sample.

However personally I find the "ON" / "OFF" approach very limited.
First with a misspell like "On", " ON", "on", "on " the procedure fails. Second, for a programmer it is highly impractical when using calculating in the parameters, e.g. PROC_pin(24, Status% MOD 2). Third, it is very uncommon, e.g. see Windows function for ShowWindow, https://docs.microsoft.com/en-us/window ... showwindow

It's of course only just my opinion.

Mike