HC-SR501: Skirtumas tarp puslapio versijų

Iš Žinynas.
Jump to navigation Jump to search
(Naujas puslapis: '''Judesio daviklis.''' 600px == Sujungimas == Visi pinai aprašyti čia. Sujungimas: VVC = PIN 2 OUTPUT = PIN 7...)
 
2 eilutė: 2 eilutė:
  
 
[[Vaizdas:Introduction-to-HC-SR501.jpg|600px]]
 
[[Vaizdas:Introduction-to-HC-SR501.jpg|600px]]
 +
 +
= RaspberryPI =
 +
 +
== Kodas ==
 +
 +
<syntaxhighlight lang="python">
 +
#!/usr/bin/python
 +
 +
import RPi.GPIO as GPIO
 +
import time
 +
import urllib
 +
 +
sensor = 8
 +
 +
GPIO.setmode(GPIO.BCM)
 +
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)
 +
 +
previous_state = False
 +
current_state = False
 +
 +
while True:
 +
  time.sleep(0.1)
 +
  previous_state = current_state
 +
  current_state = GPIO.input(sensor)
 +
  if current_state != previous_state:
 +
    new_state = "HIGH" if current_state else "LOW"
 +
    print("GPIO pin %s is %s" % (sensor, new_state))
 +
    httpresponse = urllib.urlopen ("http://xxx.xxx.xxx.xxx:8080/json.htm?type=command&param=switchlight&idx=XX&switchcmd=On")
 +
</syntaxhighlight>
 +
 +
= OrangePI =
  
 
== Sujungimas ==
 
== Sujungimas ==

20:31, 8 liepos 2019 versija

Judesio daviklis.

Introduction-to-HC-SR501.jpg

RaspberryPI

Kodas

#!/usr/bin/python

import RPi.GPIO as GPIO
import time
import urllib

sensor = 8

GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)

previous_state = False
current_state = False

while True:
  time.sleep(0.1)
  previous_state = current_state
  current_state = GPIO.input(sensor)
  if current_state != previous_state:
    new_state = "HIGH" if current_state else "LOW"
    print("GPIO pin %s is %s" % (sensor, new_state))
    httpresponse = urllib.urlopen ("http://xxx.xxx.xxx.xxx:8080/json.htm?type=command&param=switchlight&idx=XX&switchcmd=On")

OrangePI

Sujungimas

Visi pinai aprašyti čia. Sujungimas:

VVC = PIN 2
OUTPUT = PIN 7
GND = PIN 6

Kodas

from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
mq135 = port.PA6
gpio.init()
gpio.setcfg(mq135, gpio.INPUT)
try:
    while True:
        state = gpio.input(mq135)
        sleep(0.2)
        print "Statusas: %d"%state
except KeyboardInterrupt:
    print ("Goodbye.")