Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (divide)
      (equal)
      (less)
      (minus)
      (more)
      (multiply)
      (plus)
      (power)
      Abs
      And
      Append
      Asc
      Atn
      Auto
      Backup
      Bank
      Begin
      Bend
      Bload
      Boot
      Box
      Bsave
      Bump
      Catalog
      Char
      Chr
      Circle
      Close
      Clr
      Cmd
      Collect
      Collision
      Color
      Concat
      Cont
      Copy
      Cos
      Data
      Dclear
      Dclose
      Dec
      Def
      Delete
      Dim
      Directory
      Dispose
      Dload
      Do
      Dopen
      Draw
      Ds
      Ds string
      Dsave
      Dverify
      El
      Else
      End
      Envelope
      Er
      Err
      Exit
      Exp
      Fast
      Fetch
      Filter
      Fn
      For
      Fre
      Get
      Get num
      Getkey
      Go
      Gosub
      Goto
      Graphic
      Gshape
      Header
      Help
      Hex
      If
      Input
      Input num
      Instr
      Int
      Joy
      Key
      Left
      Len
      Let
      List
      Load
      Locate
      Log
      Loop
      Mid
      Monitor
      Movspr
      New
      Next
      Not
      Off
      On
      Open
      Or
      Paint
      Peek
      Pen
      Pi
      Play
      Pointer
      Poke
      Pos
      Pot
      Print
      Print num
      Pudef
      Quit
      Rclr
      Rdot
      Read
      Record
      Rem
      Rename
      Renumber
      Restore
      Resume
      Return
      Rgr
      Right
      Rlum
      Rnd
      Rreg
      Rspcolor
      Rsppos
      Rsprite
      Run
      Rwindow
      Save
      Scale
      Scnclr
      Scratch
      Sgn
      Sin
      Sleep
      Slow
      Sound
      Spc
      Sprcolor
      Sprdef
      Sprite
      Sprsav
      Sqr
      Sshape
      St
      Stash
      Step
      Stop
      Str
      Swap
      Sys
      Tab
      Tan
      Tempo
      Then
      Ti
      Ti string
      To
      Trap
      Troff
      Tron
      Until
      Using
      Usr
      Val
      Verify
      Vol
      Wait
      While
      Width
      Window
      Xor
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
POTP{Shift+O}CE 027.0Function

 Syntax 
POT adcChannel )
 
ParametersTypeLegal Value(s)Note(s)
adcChannelInteger
  1. X axis, game port 1
  2. Y axis, game port 1
  3. X axis, game port 2
  4. Y axis, game port 2
 
ReturnsTypeValue(s)Note(s)
potValueInteger
0 ~ 255 (ADC value)
+256 (button)
 
 Purpose 
Return a value indicating the state of a "paddle".
 
 Remarks 
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.
 
Examples:
PRINT POT(1)
 255                  button not pressed, max ADC value (disconnected)

READY.
PRINT POT(1)
 64                   button not pressed, ADC value 64

READY.
PRINT POT(1)
 320                  button pressed, ADC value 64 (64 + 256)

READY.
PRINT POT("1") 

?TYPE MISMATCH ERROR 
READY.
 
 Compare With 
 
 Contrast With 
 
 See Also 

© H2Obsession, 2014