raspicar/raspicar.py

68 lines
1.3 KiB
Python
Raw Permalink Normal View History

2021-01-22 18:29:59 +01:00
import time
2021-01-22 18:39:15 +01:00
import atexit
2021-01-23 19:00:02 +01:00
import configparser
2021-01-22 18:29:59 +01:00
import RPi.GPIO as GPIO
2021-01-23 22:08:40 +01:00
from sensors import Sensors
from display import Display
from network import Network
2021-01-22 18:29:59 +01:00
2021-01-23 19:00:02 +01:00
config = configparser.RawConfigParser()
config.read(r'./config.ini')
2021-01-24 12:02:05 +01:00
display = Display(config)
2021-01-23 22:08:40 +01:00
sensor = Sensors(config)
network = Network(config)
2021-01-22 18:39:15 +01:00
2021-01-22 18:29:59 +01:00
# Init program
def init():
2021-01-23 22:08:40 +01:00
# Button
BUTTON = int(config.get('button', 'BUTTON'))
2021-01-22 18:29:59 +01:00
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Add button event
GPIO.add_event_detect(BUTTON, GPIO.FALLING, callback=handlePushButton, bouncetime=250)
pass
2021-01-23 22:08:40 +01:00
# Function called on push button (change sensor)
def handlePushButton(button):
channel = sensor.getChannel() + 1
if (channel > 8):
channel = 0
2021-01-22 18:29:59 +01:00
2021-01-23 22:08:40 +01:00
sensor.setChannel(channel)
display.print(" :"+str(channel)+"-")
2021-01-22 18:29:59 +01:00
2021-01-23 22:08:40 +01:00
# On exit
def handleExit():
print("GoodBye!")
display.print("--:--")
time.sleep(2)
display.clear()
2021-01-22 18:29:59 +01:00
# Main programm
def main():
init()
print("Let's go!")
while True:
network.check()
2021-01-23 22:08:40 +01:00
display.print(sensor.getValue())
2021-01-22 18:29:59 +01:00
2021-01-23 22:08:40 +01:00
# Wait before next loop
2021-01-24 12:02:05 +01:00
time.sleep(2)
2021-01-22 18:29:59 +01:00
2021-01-22 18:39:15 +01:00
atexit.register(handleExit)
2021-01-22 18:29:59 +01:00
if __name__ =='__main__':
try:
main()
except KeyboardInterrupt:
pass