Bread baking scheduler

Got a programming project in mind? Tell everyone about it!
Post Reply
heinerwiegel
Posts: 2
Joined: Mon Jan 18, 2021 10:25 pm

Bread baking scheduler

Post by heinerwiegel »

I'm scheduling my bread baking process with the crowpi2, using the LCD, seven segment and buzzer:

Code: Select all

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author : Heiner Wiegel, Berlin, 2021
# Original Author : stenobot
# Original Author Github: https://github.com/stenobot/SoundMatrixPi
# http://elecrow.com/
from __future__ import division
import signal
import time
import sys
import threading
import datetime
import Adafruit_CharLCD as LCD
import spidev
import os
import RPi.GPIO as GPIO
from Adafruit_LED_Backpack import SevenSegment

buzzer_pin=18
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(buzzer_pin, GPIO.OUT)
col_thread=0

class GracefulKiller:
	def __init__(self):
		signal.signal(signal.SIGINT, self.exit_gracefully)
		signal.signal(signal.SIGTERM, self.exit_gracefully)

	def exit_gracefully(self, signum, frame):
		col_thread.stop()
		segment.set_colon(True)
		segment.clear()
		segment.write_display()
		lcd.clear()
		lcd.set_backlight(1)
		sys.exit()
		
class led_colon_thread(threading.Thread):
	def __init__(self):
		threading.Thread.__init__(self)
		colon_v=0
		self._is_running=True

	def run(self):
		colon_v=0
		while self._is_running:
			segment.set_colon(colon_v)
			segment.write_display()
			time.sleep(1)
			colon_v=~colon_v

	def stop(self):
		segment.set_colon(True)
		segment.write_display()
		self._is_running=False

def buzz(dur=2):
	GPIO.output(buzzer_pin, GPIO.HIGH)
	time.sleep(dur)
	GPIO.output(buzzer_pin, GPIO.LOW)
	return

def seg_time(seg_min, seg_sec=0):
	while seg_min>0 or seg_sec>0:
		segment.set_digit(0, seg_min//10)
		segment.set_digit(1, seg_min%10)
		while seg_sec>0:
			seg_sec=seg_sec-1
			segment.set_digit(2, seg_sec//10)
			segment.set_digit(3, seg_sec%10)
			time.sleep(1)
		if seg_min>0:
			seg_min=seg_min-1
			seg_sec=60
	segment.clear()
	return

def kstep(desc="Pause", dur=6):
	durs=0
	lcd.clear()
	lcd.message(desc+"\n"+str(dur)+" Minuten")
	lcd.set_backlight(0)
	seg_time(dur)
	buzz()
	lcd.clear()
	lcd.set_backlight(1)
	return

def cleanup_displays():
	col_thread.stop()
	segment.clear()
	segment.write_display()
	lcd.clear()
	lcd.set_backlight(1)
	GPIO.cleanup()
	return

try:
	segment = SevenSegment.SevenSegment(address=0x70)

	segment.begin()
	segment.clear()

	# Define LCD column and row size for 16x2 LCD.
	lcd_columns = 16
	lcd_rows    = 2

	# Initialize the LCD using the pins
	lcd = LCD.Adafruit_CharLCDBackpack(address=0x21)

	killer=GracefulKiller()

	col_thread = led_colon_thread()
	col_thread.start()

	kstep("Br\xF5hst\xF5ck", 60)
	kstep("langsam kneten 1", 12)
	kstep("schnell kneten 1", 6)
	kstep("Pause 1", 20)
	kstep("langsam kneten 2", 12)
	kstep("schnell kneten 2", 6)
	kstep("Pause 2", 20)
	kstep("langsam kneten 3", 12)
	kstep("schnell kneten 3", 6)
	kstep("240/190C, Pause3", 20)
	kstep("langsam kneten 4", 12)
	kstep("schnell kneten 4", 6)
	kstep("Aufarbeiten", 10)
	kstep("Gare", 60)
	kstep("Wasser, stippen", 5)
	kstep("Backen", 60)
	cleanup_displays()

except KeyboardInterrupt:
	cleanup_displays()
	sys.exit()

Post Reply