/*
/*
* one pot fades one motor
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
* Modified again by dave
*/
#include <math.h> //
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 br = 1000; //variable to store a value for the brightness of the room
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
if (br - val <50)
analogWrite(motorPin, 0);
else if (br - val <75)
analogWrite(motorPin, val/1000); // analogWrite can be between 0-255
else if (br-val<100)
analogWrite(motorPin, val/500);
else if (br-val<130)
analogWrite(motorPin, val/250);
else if (br-val<170)
analogWrite(motorPin, val/125);
else if (br-val<200)
analogWrite(motorPin, val/65);
else if (br-val<240)
analogWrite(motorPin, val/33);
else if( br-val<270)
analogWrite(motorPin, val/15);
else if (br-val<320)
analogWrite(motorPin, val/7); // analogWrite can be between 0-255
else if( br-val<380)
analogWrite(motorPin, val/2);
else if (br-val<450)
analogWrite(motorPin, val);
else if (br-val>450)
analogWrite(motorPin, 0); //do something cool
}