#:import SwapTransition kivy.uix.screenmanager.SwapTransition
<Greenbutton@Button>
background_color:(0,1,0,1)
<Redbutton@Button>
background_color:(1,0,0,1)
ScreenManager:
transition: SwapTransition()
Screen:
name: 'home'
BoxLayout:
orientation: "vertical"
padding: 100
spacing: 50
Greenbutton:
text: 'Steuerung'
on_press: root.current = 'control'
Greenbutton:
text: 'PLATZHALTER'
Screen:
name: 'control'
BoxLayout:
orientation: "vertical"
BoxLayout:
size_hint: 1.0, 0.05
Label:
id: 'label_1'
font_size: 25
text:'Wagi-Pi Control Center'
GridLayout:
size_hint: 1.0, 0.95
cols: 3
padding:10
spacing: 5
Redbutton:
text: 'MENU'
on_press: root.current = 'home'
Button:
id: allOnButton
text: 'ALL ON'
on_press: app.all_on()
Button:
id: allOffButton
text: 'ALL OFF'
on_press: app.all_off()
ToggleButton:
id: doorButton
text: 'DOOR'
ToggleButton:
id: middleButton
text: 'MIDDLE'
ToggleButton:
id: bedButton
text: 'BED'
Button:
id: dimModeButton
text: 'DIM MODE'
on_press: root.current = 'dim'
Button:
id: pressButton
text: 'PRESS'
Button:
id: beepButton
text: 'BEEP'
ToggleButton:
id: gpio1Button
text: 'GPIO 1'
ToggleButton:
id: gpio2Button
text: 'GPIO 2'
ToggleButton:
id: gpio3Button
text: 'GPIO 3'
Screen:
name: 'dim'
BoxLayout:
orientation: "vertical"
Label:
id: label_slider1
text: '50'
Slider:
id: slider1
orientation: 'horizontal'
min: 0
max: 100
value: 50
on_touch_down: app.update_pwm1(self,value)
on_touch_move: app.update_pwm1(self,value)
Label:
id: label_slider2
text: '50'
Slider:
id: slider2
orientation: 'horizontal'
min: 0
max: 100
value: 50
on_touch_down: app.update_pwm2(self,value)
on_touch_move: app.update_pwm2(self,value)
Label:
id: label_slider3
text: '50'
Slider:
id: slider3
orientation: 'horizontal'
min: 0
max: 100
value: 50
on_touch_down: app.update_pwm3(self,value)
on_touch_move: app.update_pwm3(self,value)
# Imports
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.togglebutton import ToggleButton
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.slider import Slider
from kivy.clock import Clock
from kivy.graphics import Color, Rectangle
import RPi.GPIO as GPIO
# initialize PWM duty cycle 50 from 100
pwm1 = 50
pwm2 = 50
pwm3 = 50
# if you press it output will be HIGH for 0.1 second standard
beepLedPin = 11
# normal on/off triggered outputs with LED's in my example
gpio1 = 19
gpio2 = 21
gpio3 = 23
# output is HIGH while pressed, will fall LOW on release
pressedLedPin = 13
# outputs dimmed with PWM | sliders to dimm
pwmLedPin1 = 15
pwmLedPin2 = 12
pwmLedPin3 = 16
# initialize GPIO's as
GPIO.setmode(GPIO.BOARD)
GPIO.setup(beepLedPin, GPIO.OUT)
GPIO.output(beepLedPin, GPIO.LOW)
GPIO.setup(gpio1, GPIO.OUT)
GPIO.output(gpio1, GPIO.LOW)
GPIO.setup(gpio2, GPIO.OUT)
GPIO.output(gpio2, GPIO.LOW)
GPIO.setup(gpio3, GPIO.OUT)
GPIO.output(gpio3, GPIO.LOW)
GPIO.setup(pressedLedPin, GPIO.OUT)
GPIO.output(pressedLedPin, GPIO.LOW)
GPIO.setup(pwmLedPin1, GPIO.OUT)
GPIO.setup(pwmLedPin2, GPIO.OUT)
GPIO.setup(pwmLedPin3, GPIO.OUT)
# Start PWM outputs with 100Hz
RPWM1 = GPIO.PWM(pwmLedPin1, 100)
RPWM1.start(pwm1)
RPWM2 = GPIO.PWM(pwmLedPin2, 100)
RPWM2.start(pwm2)
RPWM3 = GPIO.PWM(pwmLedPin3, 100)
RPWM3.start(pwm3)
# pass this because we have our wagipi.kv file
class WagipiApp(App):
pass
################### Now we need our helper functions ###################
# Our callback when a button gets pressed
def press_cb(self):
print("Button pressed: ", self.text)
# !!! NOT FINISHED !!!
# Our callback when a button gets released | only relevant for our "pressedLedPin"
def release_cb(self):
print("Button released: ", self.text)
# !!! NOT FINISHED !!!
# Our help function to turn off our beepLedPin after the time schedule
def beep_off():
GPIO.output(beepLedPin, GPIO.LOW)
# This is called when the slider for pwm1 is updated:
def update_pwm1(self,value):
global pwm1
print("Dim pwm1 to:" + str(self.value))
pwm1 = self.value
RPWM1.ChangeDutyCycle(pwm1)
# This is called when the slider for pwm2 is updated:
def update_pwm2(self,value):
global pwm2
print("Dim pwm2 to:" + str(self.value))
pwm2 = self.value
RPWM2.ChangeDutyCycle(pwm2)
# This is called when the slider for pwm3 is updated:
def update_pwm3(self,value):
global pwm3
print("Dim pwm3 to:" + str(self.value))
pwm3 = self.value
RPWM3.ChangeDutyCycle(pwm3)
def all_off(dt):
GPIO.setup(pwmLedPin1, GPIO.IN)
GPIO.setup(pwmLedPin2, GPIO.IN)
GPIO.setup(pwmLedPin3, GPIO.IN)
def all_on(dt):
GPIO.setup(pwmLedPin1, GPIO.OUT)
GPIO.setup(pwmLedPin2, GPIO.OUT)
GPIO.setup(pwmLedPin3, GPIO.OUT)
meineAnwendung=WagipiApp()
print(meineAnwendung)
meineAnwendung.run()