
Vibrations-Sensor + 4LEDs
Mai 8, 2008
Hallo
Für alle die auch einen Vibrationssensor haben, oder ein solches Gebilde nachbauen möchten – hier der „Schaltplan“ und das Script.
Viel Spaß dabei
Lena Dörr
/* Vibrationssensor + 4leds
* ———————–
*/
int APin = 1 ; // choose the input pin
int BPin = 2 ;
int CPin = 3 ;
int DPin = 4 ;
int LED1 = 5 ; //choose the pin for the LED
int LED2 = 6 ;
int LED3 = 7 ;
int LED4 = 8 ;
int val = 0; // variable for reading the pin status
void setup ( ) {
pinMode (APin, OUTPUT); //
pinMode (BPin, INPUT); //declare the input
pinMode (CPin, OUTPUT); //
pinMode (DPin, INPUT); //
pinMode (LED1, OUTPUT); //declare the LED as OUTPUT
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);
pinMode (LED4, OUTPUT);
}
void loop() {
//A1=APin =High A2=CPin =LOW
digitalWrite(APin, HIGH); //
digitalWrite(CPin, LOW ); //
//prüfen ob e1 =high:
val = digitalRead(BPin); //read input value
if (val == HIGH) {
digitalWrite(LED1, HIGH ); // turn LED on = Neigung VOR
}
else {
digitalWrite(LED1, LOW ); // turn LED off = Mitte oder Neigung zu andere Kante
}
//prüfen ob e2=high:
val = digitalRead(DPin); //read input value
if (val == HIGH) {
digitalWrite(LED2, HIGH ); // turn LED on = Neigung LINKS
}
else {
digitalWrite(LED2, LOW ); // turn LED off = Mitte oder Neigung zu andere Kante
}
//A1=Apin =LOW A2=CPin=high
digitalWrite(APin, LOW); //
digitalWrite(CPin, HIGH ); //
//prüfen ob e1 =high
val = digitalRead(BPin); //read input value
if (val == HIGH) {
digitalWrite(LED4, HIGH ); // turn LED on = Neigung RECHTS
}
else {
digitalWrite(LED4, LOW ); // turn LED off = Mitte oder Neigung zu andere Kante
}
//prüfen ob e2=high
val = digitalRead(DPin); //read input value
if (val == HIGH) {
digitalWrite(LED3, HIGH ); // turn LED on = Neigung Rück
}
else {
digitalWrite(LED3, LOW ); // turn LED off = Mitte oder Neigung zu andere Kante
}
}


