/*
* FSR controls motor
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
* Modified again by dave
* Modified again by Justin
*/
int potPin = 0; // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
int mappedVal = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
mappedVal = val/2;
if (mappedVal>255) { // guard against mappedVal exceeding maximum analogWrite
mappedVal = 255;
}
analogWrite(motorPin, mappedVal); // analogWrite can be between 0-255
}