-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsc8gpio.py.save
executable file
·31 lines (24 loc) · 1.06 KB
/
sc8gpio.py.save
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- coding: utf-8 -*-
print u"Content-type: text/html; charset=utf-8\n\n"
#mycomment=работа с GPIO
import RPi.GPIO as GPIO
print GPIO.VERSION
print GPIO.RPI_REVISION
from time import sleep # this lets us have a time delay (see line 12)
GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering
GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # set GPIO25 as input (button)
GPIO.setup(24, GPIO.OUT) # set GPIO24 as an output (LED)
try:
while True: # this will carry on until you hit CTRL+C
if GPIO.input(25): # if port 25 == 1
print "Port 25 is 1/HIGH/True - LED ON"
GPIO.output(24, 1) # set port/pin value to 1/HIGH/True
else:
print "Port 25 is 0/LOW/False - LED OFF"
GPIO.output(24, 0) # set port/pin value to 0/LOW/False
sleep(0.1) # wait 0.1 seconds
finally: # this block will run no matter how the try block exits
GPIO.cleanup() # clean up after yourself
#set free all GPIO
GPIO.cleanup()