//---  adaptation of Arduino "knock" example code
//
//--- Setup: - knock (analog) sensor:  
//             Wire a 1 meg resistor and a piezo disk in PARALLEL
//             between analog pin 1 (pin A1) 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 = 1;           // variable for analog pin as A1
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
}