//---  adaptation of Arduino "knock" example code
//
//--- Setup: - knock (analog) sensor:  
//             Wire a 1 meg resistor and a piezo disk in parallel
//             between analog pin A4 and ground. 
//            
//     - Wire an LED through 330 ohm resistors from pin 7 to gnd
//-----------------------------------------------------------------------

const int THRESHOLD = 100;
int r;                       // Create variable for storing analog readings 
int sensorPin = A4;           // variable for analog pin as A4
int LEDpin = 7;              // variable for LED pin

void setup() {  
   pinMode(LEDpin, OUTPUT);         // set digital pin as output
  }

void loop() {                      // Loop forever
    r = analogRead(sensorPin);     // get 10 bit analog value, store in r
    delay(20);                     // delay 20 milliseconds
    if (r > THRESHOLD) {           // If voltage > threshold, then:
      digitalWrite(LEDpin, HIGH);  // set LED pin high
    } else {                       // Otherwise:
      digitalWrite(LEDpin, LOW);   // set LED pin low
       }                     // end if-else
}                     // end loop