Description:
I created a force sensetive foot pedal which makes stick figures dance on the screen. The foot pedal is made up of two layers of cardboad with a pointed eraser a force sensor in between. By default there is a one cm gap between the eraser tip and the sensor so that theyhdo not touch accidentally or by light force.
Componenets used:
1 Arduino board
1 LED
1 220ohm resistor
1 110ohm resistor
1 Force sensor
Code:
// Arduino
// same as the one used in class
/*
* one pot fades one led
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int potPin = 2; // select the input pin for the potentiometer
int ledPin = 9; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
analogWrite(ledPin, val/4); // analogWrite can be between 0-255
}1a_SinglePotControlsBrightness_01a_SinglePotControlsBrightness_01a_SinglePotControlsBrightness_0
// Processing
// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="moonwalk.jpg"; */
PImage img; // Declare variable "a" of type PImage
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbmodem1421"; // or "COM5"
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(126 , 126);
frameRate(10);
smooth();
background(40,40,40);
noStroke();
// prints list of the serial port
println(Serial.list());
port = new Serial(this, Serial.list()[8], 9600);
// The image file must be in the data folder of the current sketch
// to load successfully
// img = loadImage("1.jpg"); // Load the image into the program
}
void draw() {
// // Displays the image at its actual size at point (0,0)
// image(img, 0, 0);
// // Displays the image at point (0, height/2) at half of its size
// image(img, 0, height/2, img.width/2, img.height/2);
}
void make_dance(int val)
{
println("figureNumber = "+val%10);
img = loadImage(val%10+".jpg");
image(img, 0, 0);
}
void serialEvent(Serial p)
{
int c = port.read();
if (c != lf && c != cr)
{
buf += char(c);
}
if (c == lf)
{
int val = int(buf);
println("val="+val);
make_dance(val);
buf = "";
// background(40,40,40); // erase screen
}
}
- Login to post comments