This code works perfectly, when you flick the piezo it go off for a while. The downside is that the light is solid and unfaltering.
/* piezo sketch
* lights and LED when the Piezo is tapped
*/
int sensorPin = 5; // the analog pin connected to the sensor
int ledPin = 9; // pin connected to LED
int THRESHOLD = 4;
float sinVal;
int ledVal;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
int val = analogRead(sensorPin);
if (val >= THRESHOLD)
{
digitalWrite(ledPin, LOW);
delay(100000); // to make the LED visible
}
else{
digitalWrite(ledPin, HIGH);
}
}
BUUUT if I only change one thing, the "digitalWrite(ledPin, HIGH);" to "digitalWrite(ledPin, HIGH); delay(50); digitalWrite(ledPin, LOW); delay(40);" it will flicker, but it won't respond to the piezo. Which is weird bc the code is still correct. I asked lin already, anybody have any ideas?
Tuesday, December 6, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment