Our sensor was a paper thin strip with a circle pad that was a pressure sensor. The harder you squeeze the brighter the bulb got, but it never turned all the way off upon release.
int sensorPin = A0;int ledPin = 9;int sensorValue = 0;
void setup(){ pinMode(ledPin, OUTPUT);}
void loop() { sensorValue = analogRead(sensorPin); sensorValue = sensorValue/3; analogWrite(ledPin, sensorValue); //delay();}
Analog In/Out Serial: "Amy is ____ Beautiful"
*/
// the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
int count = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
count = count + 1;
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
//Serial.print("sensor = " );
//Serial.print(sensorValue);
//Serial.print("\t output = ");
Serial.print("Amy is");
Serial.print(count);
Serial.println( "x beautiful");
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}
Ashley, one way you could deal with the light not turning all the way off is to subtract whatever the baseline reading is (the value when you aren't pressing it) from the sensor variable before you write it to the light. that way, it will write (0) when you aren't pressing the sensor.
ReplyDelete