BPI-M2+ simulated 4bits binary number increase by 4 LEDs


(Bae0497) #1

Hello Guys!

I am a beginner player. I tried some practices on GPIO.

This is my example, hopes you guys like it.

First I build a test.sh for setting GPIO through shell script.

Then build the main.sh for this example.

#!/bin/bash
echo "start main process"
PinArray=(12 14 3 66 67 71 19)
#when initial is done, use green light to notice
sudo bash test.sh 71 1
sleep 0.5
sudo bash test.sh 71 0
D2B=({0..1},{0..1},{0..1},{0..1})
#https://stackoverflow.com/questions/10278513/bash-shell-decimal-to-binary-base-2-conversion
count=0
max=15
while [ $count -le $max ];do
    outputLayout=`echo ${D2B[$count]}`
    sudo bash test.sh 66 `echo $outputLayout|awk -F '' '{print $1}'`
    sudo bash test.sh 3 `echo $outputLayout|awk -F '' '{print $2}'`
    sudo bash test.sh 14 `echo $outputLayout|awk -F '' '{print $3}'`
    sudo bash test.sh 12 `echo $outputLayout|awk -F '' '{print $4}'`
    count=$(( $count + 1 ))
    sleep 0.5
done
#when the work is done, use purple light to notice
sudo bash test.sh 19 1
sudo bash test.sh 67 1
echo "clear all target pin"
for pin in ${PinArray[@]};do
    sudo bash test.sh $pin 0
done