Skip to content
Permalink
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 (http://matlo.me)
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);
println(Arduino.list());
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);
noStroke();
}
void draw() {
background(200);
//get the potentiometer values
float val = pot.get();
//calibration
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
fill(255);
rectMode(CENTER);
rect(val, height/2, 50, 50);
//print the potentiometer values
println(val);
}
You can’t perform that action at this time.