Shop OBEX P1 Docs P2 Docs Learn Events
Trying to use a function or a sub to return a value on demand. Not working for — Parallax Forums

Trying to use a function or a sub to return a value on demand. Not working for

eagletalontimeagletalontim Posts: 1,399
edited 2008-06-18 03:27 in General Discussion
This has to be something simple. I am attempting to call a function to fill a variable. This is in relation to my RPM detection post.

Here is a sample of what I am trying to do :

getrpm SUB 0

Main:
currentrpm = getrpm
' CODE TO DISPLAY RPM
...
...
...
Goto Main

getrpm:
...
...
...
RETURN rpm


What am I doing wrong? It is getting dark outside and I am running out of time to test this [noparse]:([/noparse]

Comments

  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-06-18 00:50
    You have terms confused: SUBs aren't really intended to return values, though the can -- but to do so is sloppy programming (my opinion, yours may differ). Redefine like this:

    GET_RPM         FUNC    1, 0
    


    Then code the function like this:

    FUNC GET_RPM
      ...
      RETURN RPM
      ENDFUNC
    


    If the RPM value can be a word then you need to change the declaration to 2.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-06-18 00:56
    what do you mean by declaration?
  • BeanBean Posts: 8,129
    edited 2008-06-18 01:37
    Typically SUBs don't return a value.
    FUNCs do.

    FUNCs are declared as:
    name FUNC returnbytes, sendbytesmin{,sendbytesmax}

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    That was on fire when I got here...

    www.iElectronicDesigns.com

    ·
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-06-18 02:24
    ok, two more questions tongue.gif

    1st : Is there any way to detect ohms? Like if I had a potentiometer connected between ground and a pin, could the chip process the ohm rating or calculate it into a percentage? Example : 0 ohms = 100%, 100k ohms = 0%

    2nd : Can a pin be programmed to have a gradual increase or decrease in voltage out?
  • BeanBean Posts: 8,129
    edited 2008-06-18 02:33
    1st: Use the RCTime command

    2nd: Use the PWM command

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Uhhhm, that was on fire when I got here...

    www.iElectronicDesigns.com

    ·
  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-06-18 03:27
    Just a suggestion: don't change the topic of a thread mid-way through; makes it hard for people to find information when scanning topic titles.
Sign In or Register to comment.