Wednesday, December 16, 2009

Prototype #8

Description:
By bending the piezo tab back and forth we are now able read variable output values in the serial monitor in Arduino interface.

Input:
Piezo Film

Output:
Serial read of values in Arduino

Setup:















Result:

Code:
int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3 // outside leads to ground and +5V
int ledPin = 13; // LED connected to digital pin 9
int val = 0; // variable to store the value read
void setup()
{
Serial.begin(9600); // setup serial
pinMode(ledPin, OUTPUT); // sets the pin as output
}
void loop()
{
val = analogRead(analogPin)/4; // read the input pin
Serial.println(val); // debug value
val = analogRead(analogPin); // read the input pin
digitalWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}


Labels: , ,


Comments:

Post a Comment





<< Home

This page is powered by Blogger. Isn't yours?