Έλεγχος Led με χειροκρότημα

 

http://s3.amazonaws.com/img.iluria.com/product/22C645/5241CF/450xN.jpg

 

int soundSensor=2;
int LED=4;
boolean LEDStatus=false;

void setup() {
pinMode(soundSensor,INPUT);
pinMode(LED,OUTPUT);

}

void loop() {

int SensorData=digitalRead(soundSensor);
if(SensorData==1){

if(LEDStatus==false){
LEDStatus=true;
digitalWrite(LED,HIGH);
}
else{
LEDStatus=false;
digitalWrite(LED,LOW);
}
}
}

 

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 4; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup ()
{
pinMode (ledPin, OUTPUT);
Serial.begin (9600);
}

void loop ()
{
sensorValue = analogRead (sensorPin);
digitalWrite (ledPin, HIGH);
delay (sensorValue);
digitalWrite (ledPin, LOW);
delay (sensorValue);
Serial.println (sensorValue, DEC);
}