test

int knockSensor = 0;

byte val = 0;

int THRESHOLD = 5;

int redPin = 12; // Red LED, connected to digital pin 9
int greenPin =11; // Green LED, connected to digital pin 10
int bluePin =10; // Blue LED, connected to digital pin 11

void setup() {

Serial.begin(9600);
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

}
void loop() {

val = analogRead(knockSensor);

if (val >= THRESHOLD) {
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);

Serial.println(“Knock!”);

}

else{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}

delay(50
);

}

Leave a Reply

Your email address will not be published.