View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
How to define a function to port |
Posted: Wed Oct 07, 2020 9:46 am |
|
|
Hi, how can I define a function that monitors the logical state of an input already defined?
here I define the port:
Code: | #define btonPANIC input(PIN_B0)
#define pulsosRTC PIN_B1
#define btonTEST input(PIN_B2) |
here I want to define the function but how do I relate it to the port?
Code: | void debounce(btonPANIC ????????, char flag){
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Wed Oct 07, 2020 9:58 am |
|
|
How old is your compiler?.
On old compilers, pin numbers have to be a constant, so can't be passed
like this (well can be using some old code that was posted here, but
not using the standard functions). On newer compilers the value can
be a variable:
Code: |
void debounce(int16 pin_to_use, char flag){
x=input(pin_to_use);
//will then access the specified pin.
}
|
However _beware_ it takes dozens of instructions to access a pin declared
as a variable, against just a couple for direct access. So if you want real
speed 'think again'.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Oct 07, 2020 2:03 pm |
|
|
Someone converted the 'button.c' function from PBasic(?) years ago. I think it's in the 'code' forum, well, pretty sure...
Old brain matter isn't um, ah, what it, er, used to be....
Jay |
|
|
|