-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardware_control.py
65 lines (56 loc) · 1.89 KB
/
hardware_control.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import RPi.GPIO as GPIO
import datetime
import time
import os
"""
/ o---Cooling
/ o---x |-----o-/
|---o-/ | o---Heating (relais light on)
| o-------| Relais4
| Relais3
|
/ o---x OFF |
230V ---o-/ | / o---x
o--- ON ------|---o-/
o---Light (25A light relais)
Relais1 Relais2
"""
class hardware_control:
# Relais control:
onoff_pin = 6# Relais1, black
light_pin = 13 # Relais2, white
temp_en_pin = 19 # Relais3, blue
cooling_heating_pin = 26 # Relais4, red
is_on = GPIO.HIGH
is_off = GPIO.LOW
def __init__(self):
pass
def hw_setup(self):
GPIO.setmode(GPIO.BCM) # alternative: GPIO.BOARD
GPIO.setup(hardware_control.onoff_pin, GPIO.OUT)
GPIO.output(hardware_control.onoff_pin, hardware_control.is_off)
GPIO.setup(hardware_control.light_pin, GPIO.OUT)
GPIO.output(hardware_control.light_pin, hardware_control.is_off)
GPIO.setup(hardware_control.temp_en_pin, GPIO.OUT)
GPIO.output(hardware_control.temp_en_pin, hardware_control.is_off)
GPIO.setup(hardware_control.cooling_heating_pin, GPIO.OUT)
GPIO.output(hardware_control.cooling_heating_pin, hardware_control.is_off)
return
def control_pin(self, pin, state):
GPIO.output(pin, state)
return
def cleanup(self):
"""
hc = hardware_control.hardware_control()
...
try:
...
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
print("Program aborted by user keyboard interrupt")
hc.cleanup()
"""
print("Cleaning up RasPi GPIO.")
GPIO.cleanup() # Release resource
print("Cleaning up RasPi GPIO finished. Bye.")
return