View unanswered posts | View active topics It is currently Wed Apr 16, 2014 11:52 pm






Reply to topic  [ 2 posts ] 
Potentiometers 
Author Message
Rookie

Joined: Thu Jul 08, 2010 3:50 pm
Posts: 18
Post Potentiometers
It seems there is little info in the sample programs as to how to retrieve data from a potentiometer, please help with any available info. Thanks.


Thu Jul 08, 2010 3:55 pm
Profile
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: Potentiometers
Hi,

You can read the values of the Potentiometer Sensor just like any other sensor, by using the
Code:
SensorValue(potentiometerSensor);
command.

For the VEX2.0 Cortex, the Potentiometer returns values from 0 to 4095, however due to the mechanical design there may be physical stops, limiting the actual reading from 5 to 4090 or so. This seems to range from sensor to sensor so just plug yours in and see what you get.

Below is a program that reads the values of a Potentiometer Sensor attached to Analog Sensor Port 6, and displays the values to the VEX LCD. If you don't have an LCD, you can just as easily (and more accurately) see the values in the ROBOTC Debugger under the "Sensors" tab (Robot > Debug Windows > Sensors)
Code:
#pragma config(ProgramType, StandaloneWiFi)
#pragma config(UART_Usage, UART2, VEX_2x16_LCD)
#pragma config(Sensor, in6,    potentioSensor,      sensorPotentiometer)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  while(true)
  {
    clearLCDLine(1);                                      // Clear LCD Bottom Line
   
    displayLCDPos(1,0);                                   // Set the cursor to bottom line, first position
    displayNextLCDString("Potentio: ");                   // Print "Potentio: " starting at the cursor position
   
    displayNextLCDNumber(SensorValue(potentioSensor));    // Display the reading of the Potentiometer to current cursor position
   
    wait1Msec(150);                                       // Wait 150 milliseconds to help the LCD refresh nicely
  }
}


Attachments:
potentiometerTest.c [858 Bytes]
Downloaded 389 times

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学
Wed Jul 14, 2010 9:40 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.