//CONSTANTSconst int numberOfValues = 10; //number of values to remember at a timeconst int numberOfZerosNeeded = 3; //number of zeros needed in all the values for the switch to be considered pressedconst int lowValueThreshold = 100; //threshold for a value to be considered 0const int ledPin = 6; //pin for the lightconst int inputPin = 3; //pin for the input//last # values received from the input pinsint values[numberOfValues];int currentValue = 0; //increment everytime//initvoid setup() { //setup arduino Serial.begin(9600); //setup the led pinMode(ledPin,OUTPUT); digitalWrite(ledPin,LOW); //setup the values for (int i=0; i<numberOfValues; i++) values[i] = 0;}//main loopvoid loop() { //read the value for the pin int value = analogRead(3); //change the average value values[currentValue] = value; currentValue++; if (currentValue>=numberOfValues) currentValue = 0; //get the number of zeros int numberOfZeros = 0; for (int i=0;i<numberOfValues; i++) { if (values[i] < lowValueThreshold) numberOfZeros++; } //light the pin or close it if needed if (numberOfZeros > numberOfZerosNeeded) { digitalWrite(ledPin,HIGH); } else { digitalWrite(ledPin,LOW); } // Serial.println( value ); delay(100);}