1 changed files with 64 additions and 0 deletions
@ -0,0 +1,64 @@ |
|||
#! /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 |
|||
|
|||
|
Loading…
Reference in new issue