Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # eg. bash generic-wave-pigpio.sh 25 3000 10
- #
- # Creates 3kHz 10% duty cycle on GPIO 25
- # 3kHz 10% duty cycle -> 30microseconds on, 300 microseconds off
- # If accuracy problems, /boot/config.txt dtparam=audio=off
- #set -x
- G="$1"
- freq="$2"
- duty="$3"
- usage() {
- echo "$0 GPIO freq duty"
- exit 1
- }
- [ $G ] || usage
- [ $freq ] || usage
- [ $duty ] || usage
- period=$(python -c "print(1000000/$freq)")
- on=$(python -c "print(int($period *$duty/100.0))")
- off=$((period - on))
- pigs m $G w
- pigs wvag $((1<<$G)) 0 $on 0 $(( 1<<$G)) $off
- wid=$(pigs wvcre)
- pigs wvtxr $wid
- # stop waveform by running:
- # pigs wvhlt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement