![]() |
[OCCRA]: Potentiometer Code
Hey I was wondering if anyone had some basic code for the use of potentiometer, or else some basic assistance would be greatly appreciated.
Thanks |
Re: [OCCRA]: Potentiometer Code
Is this for a big robot or a VEX robot? What do you want to do with the potentiometer?
I assume that you want to use a motor to go to a certain position. In that case, the code would go something like: (in MPLAB C) Code:
//Do not simply use this code. Before you do this, always use the serial output to check and see that moving the motor forward causes the sensor to move in the same direction. Code:
printf("Pot: ");Code:
pot = 255 - pot;It would be good programming practice to write checking code that sees if the sensor is out of bounds and limits the motor to go in one direction only, and stops it all together or switches control directly to the joystick if the sensor is too far out of bounds. When we wrote the crab-drive code for our FIRST robot, we did not include this in our early test versions, and the motors were inverted, and all of the pods started spinning around and around, breaking all of the sensors. If the sensor never physically gets to 0, you can assume 0 means the sensor is unplugged. That can happen. If you went to the workshop (the regular workshop, not the VEX workshop), Jim Zondag taught a class on this. This is the same principle. It would be much easier to explain if I had an example to show. It took me about half an hour to understand once it was explained to me (and I drew some pictures on the whiteboard to understand it). Any questions? Don't forget semicolons if you are using C. If you are using EasyC, then the same principle still applies. You just need to apply it. |
| All times are GMT -5. The time now is 21:45. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi