![]() |
Digital I/O Help
How do I use the I/O's to sense an external input, such as a switch, particularly a limit switch. For example, if I want to count how many times the switch was pressed, meaning that the digital input detects a "high" signal and can then count a variable each time this happens, in code. I been trying to mess with it but I do not much experience with this type of custom configuration. I been trying to set up the digital inputs to detect a high signal and then a different one output a certain signal but with no luck. Thanks for any help with this.
|
Re: Digital I/O Help
There are two ways you can do what you want. The first is the easy way:
The second way involves using interrupts and is slightly more difficult, but necessary if you are going to be getting digital IO state changes at a high rate. (An encoder on a drive wheel would be an example of something which typically needs interrutps.) |
Re: Digital I/O Help
The digital inputs on the RC will read as "1" when open, and "0" when grounded. They will directly detect contact closures to ground, such as a limit switch or an Allen-Bradley optical sensor.
If you want your code to count switch activations, you should remember that you only want to increment the count when the read value changes from 1 to 0. Code:
if (last_rc_dig_07 == 1 && rc_dig_07 == 0) |
| All times are GMT -5. The time now is 17:30. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi