Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎


Keyword Abbreviation Token (hex) Version(s) Classification
POT P{Shift+O} CE 02 7.0 Function

POT adcChannel )
Parameters Type Legal Value(s) Note(s)
adcChannel Integer
  1. X axis, game port 1
  2. Y axis, game port 1
  3. X axis, game port 2
  4. Y axis, game port 2
Returns Type Value(s) Note(s)
potValue Integer
0 ~ 255 (ADC value)
+256 (button)
Return a value indicating the state of a "paddle".
The POT function is used for "commuicating" with a paddle, mouse, or graphics tablet).  Similar to the screen and keyboard in that the direction is one-way and you don't need to OPEN a "file" to communicate.  Unlike the screen and keyboard, you can't open a file to a paddle/mouse.  Trivia: POT is short for potentiometer, which is a long word for variable resistor. 
Paddles almost always come as a pair (the pair plugs into a single "game port", see JOY).  Paddles never were very popular with C64 / C128, so the only one (err, pair) that I know about is the Commodore 1312.  Paddles for the Atari 2600 wouldn't work well with a Commodore because of different resistor values needed.  Each one in the set has a knob that can be twisted, which is simply a potentiometer, plus a button.  Each paddle uses a seperate adcChannel.  Hardware note: the buttons on a set of paddles will activate the "left" and "right" directions when read with JOY, corresponding to adcChannels 1 and 2 for game port 1 (or adcChannels 3 and 4 for game port 2).
A mouse is one device, but it uses both adcChannels of the same game port.  A nice one is the Commodore 1351.  It is conceivable an "analog" joystick might be found that uses a pair of adcChannels, somewhat like a mouse (this was common for joysticks on IBMs back in the day), although I have never seen one for a Commodore.  Hardware note: the buttons on a classic 2-button mouse will active the "fire" (left click) and "up" (right click) when read with JOY.  Neither of these buttons will be detected by POT.  Not sure about the middle button of a 3-button mouse.
A touch tablet is one device which also uses both adcChannels of the same game port.  The only one I know about for Commodores is the Koala Pad.  It is conceivable an "analog" joystick might be found that uses a pair of adcChannels, somewhat like a touch tablet (i.e., a "center" coordinate would mean the stick is centered).  Analog joysticks were common with IBMs back in the day (mostly USB game pads these days), although I have never seen one for a Commodore.  Hardware note: the buttons on a Koala Pad are reported to be the same as used by paddles, which means they can be read with POT (I don't actually own a Koala Pad, mind you).
Because there are two adcChannels per game port, and two game ports there are a total of 4 adcChannels.  The parameter adcChannel selects which of the four physical lines are to be sampled by an Analog to Digital Converter (ADC).  Values 1 and 2 of adcChannel refer to the "X" and "Y" lines of game port 1, while values 3 and 4 refer to the "X" and "Y" lines of game port 2.  The names "X" and "Y" really have no meaning for a paddle, but for a mouse or touch pad they refer (respectively) to horizontal (lef/right) position (or motion) and vertical (up/down) position (or motion).
Do the nature of analog to digital conversion, it is common for a reading to fluctuate between two values on real hardware (VICE is a nice emulator, but it gives rock-solid readings which can lead to bugs in software).  This is known as quantization noise.  The ADC value will be 0 to 255 (in theory), and this is the basis of potValue (in reality, the value usually won't go below 4).  If the paddle button corresponding to the choosen adcChannel is pressed, then 256 is added to the returned potValue.  As discussed above, neither mouse button is the same as either paddle button.  This means with a mouse connected to a game port, the potValue should always be 0 to 255; use JOY to check for mouse clicks.
To isolate the ADC value from any unwanted button reading, use the BASIC expression POT(adcChannel) AND 255.  To test for a paddle button, use POT(adcChannel) AND 256.  To test for mouse buttons, use JOY(gamePort) AND 129.
Note that to effectively read a mouse, you need to take multiple readings from an adcChannel and calculate the difference between reading to determine the speed and direction of mouse motion.  Commodore BASIC is generally to slow to do this accurately, and more important, it must be done "continuously" which means your BASIC program couldn't do much else!  So you generally need an ML program to use a mouse.
Reading from paddles or touch tablet is far easier.  With them it is easy to write a BASIC "Etch-a-Sketch" program.  With a touch tablet, you have more freedom than paddles because you can actually lift then pen off the tablet.
If adcChannel is omitted or is not a valid expression, SYNTAX ERROR occurs.  If adcChannel is a string, TYPE MISMATCH ERROR occurs; you can use VAL to make a string numeric.  Otherwise the adcChannel is converted with INT.  If the result is not a Legal Value (1 to 4) then ILLEGAL QUANTITY ERROR occurs.
 255                  button not pressed, max ADC value (disconnected)

 64                   button not pressed, ADC value 64

 320                  button pressed, ADC value 64 (64 + 256)

  Compare With  
  Contrast With  
  See Also  

© H2Obsession, 2014