You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.3 KiB
64 lines
1.3 KiB
#! /usr/bin/bash
|
|
|
|
pin_rot=17 # z.B. Pin 11 (BCM 17)
|
|
pin_gelb=27 # z.B. Pin 13 (BCM 27)
|
|
pin_gruen=22 # z.B. Pin 15 (BCM 22)
|
|
|
|
state_rot=0
|
|
state_gelb=0
|
|
state_gruen=0
|
|
|
|
gpiochip="gpiochip0"
|
|
|
|
function resetPins() {
|
|
echo "Ampel aus"
|
|
gpioset "${gpiochip}" ${pin_rot}=0 ${pin_gelb}=0 ${pin_gruen}=0
|
|
}
|
|
|
|
function setPins() {
|
|
echo "rot=${state_rot} gelb=${state_gelb} grün=${state_gruen}"
|
|
gpioset "${gpiochip}" ${pin_rot}=${state_rot} ${pin_gelb}=${state_gelb} ${pin_gruen}=${state_gruen}
|
|
}
|
|
|
|
while true
|
|
do
|
|
AUSWAHL=($(whiptail --title "Ampelsteuerung" --checklist "manuelle Steuerung" 25 75 3 \
|
|
"RED" "Rot " ${state_rot} \
|
|
"YELLOW" "Gelb " ${state_gelb} \
|
|
"GREEN" "Grün " ${state_gruen} 3>&1 1>&2 2>&3))
|
|
|
|
RETURNCODE=$?
|
|
|
|
if [ ${RETURNCODE} -ne 0 ]; then
|
|
echo "Abgebrochen – Programm wird beendet."
|
|
resetPins
|
|
break
|
|
fi
|
|
echo "AUSWAHL=${AUSWAHL[@]}"
|
|
|
|
state_rot=0
|
|
state_gelb=0
|
|
state_gruen=0
|
|
for farbe in "${AUSWAHL[@]}"; do
|
|
farbe_clean=$(echo "$farbe" | tr -d '"')
|
|
echo "aktuelle farbe=${farbe}"
|
|
|
|
case ${farbe_clean} in
|
|
"RED")
|
|
echo "setze State rot"
|
|
state_rot=1
|
|
;;
|
|
"YELLOW")
|
|
echo "setze State gelb"
|
|
state_gelb=1
|
|
;;
|
|
"GREEN")
|
|
echo "setze State grün"
|
|
state_gruen=1
|
|
;;
|
|
esac
|
|
done
|
|
setPins
|
|
done
|
|
|
|
|
|
|