KY-002 Erschütterungs-Schalter Modul: Unterschied zwischen den Versionen
Aus Linkerkit.de
(→Codebeispiel Raspberry Pi) |
|||
Zeile 31: | Zeile 31: | ||
==Codebeispiel Raspberry Pi== | ==Codebeispiel Raspberry Pi== | ||
− | |||
Programmierbeispiel in der Programmiersprache Python | Programmierbeispiel in der Programmiersprache Python | ||
− | <pre class="brush:py"> | + | <pre class="brush:py">import RPi.GPIO as GPIO |
− | import RPi.GPIO as GPIO | + | |
GPIO.setmode(GPIO.BCM) | GPIO.setmode(GPIO.BCM) | ||
GPIO_PIR = 24 | GPIO_PIR = 24 | ||
GPIO.setup(GPIO_PIR, GPIO.IN, pull_up_down = GPIO.PUD_UP) | GPIO.setup(GPIO_PIR, GPIO.IN, pull_up_down = GPIO.PUD_UP) | ||
− | print "KY-002 | + | print "KY-002 Test [druecken Sie STRG+C, um den Test zu beenden]" |
def printFunction(channel): | def printFunction(channel): | ||
− | print(" | + | print("Signal erkannt") |
GPIO.add_event_detect(GPIO_PIR, GPIO.RISING, callback=printFunction) | GPIO.add_event_detect(GPIO_PIR, GPIO.RISING, callback=printFunction) |
Version vom 17. Februar 2016, 13:52 Uhr
Inhaltsverzeichnis
Bild
Technische Daten / Kurzbeschreibung
Chipsatz: DS18B20 | Kommunikationsprotokoll: 1-Wire
9- 12Bit genaue Temperaturmessung im Meßbereich von –55°C bis +125°C
Pin-Belegung
Codebeispiel Arduino
int Led = 13 ;// define LED Interface int Shock = 10; // define the vibration sensor interface int val; // define numeric variables val void setup () { pinMode (Led, OUTPUT) ; // define LED as output interface pinMode (Shock, INPUT) ; // output interface defines vibration sensor } void loop () { val = digitalRead (Shock) ; // read digital interface is assigned a value of 3 val if (val == HIGH) // When the shock sensor detects a signal, LED flashes { digitalWrite (Led, LOW); } else { digitalWrite (Led, HIGH); } }
Codebeispiel Raspberry Pi
Programmierbeispiel in der Programmiersprache Python
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO_PIR = 24 GPIO.setup(GPIO_PIR, GPIO.IN, pull_up_down = GPIO.PUD_UP) print "KY-002 Test [druecken Sie STRG+C, um den Test zu beenden]" def printFunction(channel): print("Signal erkannt") GPIO.add_event_detect(GPIO_PIR, GPIO.RISING, callback=printFunction) try: while True : Current_State = GPIO.input(GPIO_PIR) except KeyboardInterrupt: GPIO.cleanup()