-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExerPot.py
More file actions
47 lines (32 loc) · 907 Bytes
/
ExerPot.py
File metadata and controls
47 lines (32 loc) · 907 Bytes
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import spidev
import time
from libsoc import gpio
from gpio_96boards import GPIO
GPIO_CS = GPIO.gpio_id('GPIO_CS')
RELE = GPIO.gpio_id('GPIO_A')
pins = ((GPIO_CS, 'out'),(RELE, 'out'),)
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz = 10000
spi.mode = 0b00
spi.bits_per_word = 8
def readtemp(gpio):
gpio.digital_write(GPIO_CS, GPIO.HIGH)
time.sleep(0.0002)
gpio.digital_write(GPIO_CS, GPIO.LOW)
r = spi.xfer2([0x01, 0xA0, 0x00])
gpio.digital_write(GPIO_CS, GPIO.HIGH)
adcout = (r[1] << 8) & 0b1100000000
adcout = adcout | (r[2] & 0xff)
print ("Valor do Pot.:%d" %adcout)
return adcout
while True:
with GPIO(pins) as gpio:
value = readtemp(gpio)
if value > 500:
gpio.digital_write(RELE, GPIO.HIGH)
time.sleep(0.5)
gpio.digital_write(RELE, GPIO.LOW)
else:
gpio.digital_write(RELE, GPIO.LOW)
time.sleep(0.5)