<commit_before>// https://www.arduino.cc/en/Tutorial/Knock

/* Knock Sensor

   This sketch reads a piezo element to detect a knocking sound.
   It reads an analog pin and compares the result to a set threshold.
   If the result is greater than the threshold, it writes
   "knock" to the serial port, and toggles the LED on pin 13.

   The circuit:
    * + connection of the piezo attached to analog in 0
    * - connection of the piezo attached to ground
    * 1-megohm resistor attached from analog in 0 to ground

   http://www.arduino.cc/en/Tutorial/Knock

   created 25 Mar 2007
   by <NAME> <http://www.0j0.org>
   modified 30 Aug 2011
   by <NAME>

   This example code is in the public domain.

 */


// these constants won't change:
const int ledPin = 13;      // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100;  // threshold value to decide when the detected sound is a knock or not


// these variables will change:
int sensorReading = 0;      // variable to store the value read from the sensor pin
int ledState = LOW;         // variable used to store the last LED status, to toggle the light

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

void loop() {
  // read the sensor and store it in the variable sensorReading:
  sensorReading = analogRead(knockSensor);

  // if the sensor reading is greater than the threshold:
  if (sensorReading >= threshold) {
    // toggle the status of the ledPin:
    ledState = !ledState;
    // update the LED pin itself:
    digitalWrite(ledPin, ledState);
    // send the string "Knock!" back to the computer, followed by newline
    Serial.println("Knock!");
  }
  delay(100);  // delay to avoid overloading the serial port buffer
}<commit_msg>knock<commit_after>// https://www.arduino.cc/en/Tutorial/Knock

/* Knock Sensor

 This sketch reads a piezo element to detect a knocking sound.
 It reads an analog pin and compares the result to a set threshold.
 If the result is greater than the threshold, it writes
 "knock" to the serial port, and toggles the LED on pin 13.

 The circuit:
 * + connection of the piezo attached to analog in 0
 * - connection of the piezo attached to ground
 * 1-megohm resistor attached from analog in 0 to ground

 http://www.arduino.cc/en/Tutorial/Knock

 created 25 Mar 2007
 by <NAME> <http://www.0j0.org>
 modified 30 Aug 2011
 by <NAME>

 This example code is in the public domain.

 */

// these constants won't change:
const int ledPin = 13;      // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 30; // threshold value to decide when the detected sound is a knock or not
const int threshold_low = 8;
const int wait = 100;    // ms

// these variables will change:
int sensorReading = 0;   // variable to store the value read from the sensor pin
int ledState = LOW; // variable used to store the last LED status, to toggle the light

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

int on = 0;
unsigned long last_time = 0;
void loop()
{
    // read the sensor and store it in the variable sensorReading:
    sensorReading = analogRead(knockSensor);
    unsigned long time = millis();
//    Serial.println(sensorReading);

    // if the sensor reading is greater than the threshold:
    if (sensorReading >= threshold)
    {
        if (!on)
            if (time - last_time >= wait)
            {
                // toggle the status of the ledPin:
                ledState = !ledState;

//                ledState=1;

                // send the string "Knock!" back to the computer, followed by newline
                Serial.println("Knock!");
                on = 1;
                last_time = time;
            }
    }
    if (sensorReading < threshold_low)
    {
        on = 0;
//        ledState=0;
    }
    
    // update the LED pin itself:
    digitalWrite(ledPin, ledState);

    //delay(100);  // delay to avoid overloading the serial port buffer
}

{'fraction_non_alphanumeric': 0.08197896749521988, 'fraction_numerical': 0.019359464627151053, 'mean_word_length': 2.5647359454855194, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5740038', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1154, 'n_words': 540}