Click To Play
int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // value read from the pot
int led = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
potValue = analogRead(potPin); // read the pot value
analogWrite(led, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
Serial.println(potValue); // print the pot value back to the debugger pane
delay(10); // wait 10 milliseconds before the next loop
}
Next the three of us worked on making a Love-O-Meter. We took a series of three sets of four LEDs in parallel and code them to respond to pressure put on a FSR by a pair of plastic lips set into a foamboard. Check out these lips:
and Gordie thankfully took over the cutting of the foam board which gets all over everything when you use the cutter in the shop.
The way the machine works is that someone kisses the lips, and the sensor would record the amount of force applied to the lips by the kisser, and then rate them either “Smooth” (the softest level, indicated by the green LEDs), “Hot Stuff” (the middle level, indicated by lighting both the green and the yellow LEDs) or a deliverer of “Total Ecstasy” (the top level, indicated by lighting the green, yellow, and red sets of LEDs).
Here’s the code:
int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // value read from the pot
int Greenled = 9; // PWM pin that the GreenLED is on. n.b. PWM 0 is on digital pin 9
int Yellowled = 10; // PWM pin that the YellowLED is on.
int Redled = 11; // PWM pin that the redLED is on.
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(Greenled,OUTPUT);
pinMode(Yellowled,OUTPUT);
pinMode(Redled,OUTPUT);
}
void loop() {
potValue = analogRead(potPin); // read the pot value
Serial.println(potValue);
if(100 <= potValue && potValue <>= 782)
{
digitalWrite(Greenled,HIGH); // turn n the Green LEDs
digitalWrite(Yellowled,HIGH); // turn on the Yellow LEDs
digitalWrite(Redled,HIGH); // turn on the Red LEDs
}
else
{
digitalWrite(Greenled,LOW); // turn off the Green LEDs
digitalWrite(Yellowled,LOW); // turn off the Yellow LEDs
digitalWrite(Redled,LOW); // turn off the Red LEDs
}
}
Here's Gordie doing a test with some flex sensors before we put the whole machine together.
Click To Play

No comments:
Post a Comment