Hi,
ich möchte mittels einer While schleife einen Code ausführen, solange ein Piezoelement gedrückt ist.
Ich kann zwar einen Code ausführen, wenn das Piezo gedrückt wird, aber das mit dem solange es gedrückt wird.
Könnt ihr meinen Code dahingehend ergänzen? Der Code unten funktioniert, macht aber nicht das was es soll.
// 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
// 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() {
sensorReading = analogRead(knockSensor);
while( sensorReading > 100 ) //while the button is pressed
{
Serial.println(sensorReading);
delay(10000);
sensorReading = 0;
}
Serial.println("Ende");
delay(100); // delay to avoid overloading the serial port buffer
}