Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (42 sloc) 1.08 KB
Linear Potentiometer Example
by Matteo Loglio (
display a rectangle whose horizontal position
depends from the potentiometer values.
remember to upload standardFirmata on the
Arduino board.
import processing.serial.*;
import cc.arduino.*;
import com.tinkerkit.*;
Arduino arduino;
//declare the potentiometer
TKPotentiometer pot;
float minVal = 1023;
float maxVal = 0;
void setup() {
size(512, 512);
arduino = new Arduino(this, Arduino.list()[0], 57600);
//for every tinkerkit component we have to pass
//the arduino and the port
pot = new TKPotentiometer(arduino, TK.I0);
void draw() {
//get the potentiometer values
float val = pot.get();
if (val < minVal) minVal = val;
if (val > maxVal) maxVal = val;
//map the values of the potentiometer
//on the width of the window
val = map(val, minVal, maxVal, 0, width);
//draw a rectangle
rect(val, height/2, 50, 50);
//print the potentiometer values
You can’t perform that action at this time.