User:Swaters3452/enes100/KnockKnockCodeRealFound

const int ledPin = 13;     // led connected to digital output pin 13 const int knockSensor = A0; // the piezo is connected to analog input pin 0 const int threshold = 300; // Sets a threshold for what constitutes a knock, this can be fiddled around with to change required volume

int knockReading = 0;     // variable to store the value read from the sensor pin int ledStatus = LOW;        // variable used to store the last LED status, to toggle the light on and off

void setup { pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT Serial.begin(9600);      // use the serial port }

void loop { // reads sensor, and stores data in knockReading knockReading = analogRead(knockSensor); // if the sensor reading is greater than the threshold: if (knockReading >= threshold) { // toggle the status of the ledPin: ledStatus = !ledStatus; // updates the LED pin itself: digitalWrite(ledPin, ledStatus); // Displays text "Knock" on the computer, and adds a new line. Serial.println("Knock!"); } delay(100);  // delay to avoid overloading the serial port }