- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, does anyone know how to pass a pin to a function? For example, i've created a function called PulseIn() which will behave similar to the arduino function PulseIn() which measures the amount of time for which a pin is high. However, right now I'm only limited to use it with a single pin. I want to expand it to be more flexible where I can pass the pin to the function and it will do its thing based on the desired pin.
Ex: int duration = PulseIn(pinName);
The duration of the pulse for the pin "pinName" will be saved to the int variable duration.
thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So based on the function you're describing I'll assume you're using the read api on the pin.
You can create a function pointer to the read API and then pass that through to your function. This would keep everything nice and contained, with very little fuss and matches the expectations of other people who use PSoC. It also isolates your code from hardware changes unlike the per-pin APIs. That said, you will have to handle if a pin_read call is for more than one pin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes with a CASE statement or IF statments and pin access APIs.
http://www.cypress.com/?rID=93401 AN86439 - PSoC® 4 - Using GPIO Pins
http://www.cypress.com/?rID=57571 AN72382 - Using PSoC® 3 and PSoC 5LP GPIO Pins
Also see system ref guide in help menu, there is a section on GPIO access.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So based on the function you're describing I'll assume you're using the read api on the pin.
You can create a function pointer to the read API and then pass that through to your function. This would keep everything nice and contained, with very little fuss and matches the expectations of other people who use PSoC. It also isolates your code from hardware changes unlike the per-pin APIs. That said, you will have to handle if a pin_read call is for more than one pin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the fast responses!
I shall try what both of you mentioned tomorrow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can't see any attachment with your post. Would you mind posting it again as I would be interested in reading it? 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content