Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # eg. bash generic-wave-pigpio.sh 25 3000 10
  3. #
  4. # Creates 3kHz 10% duty cycle on GPIO 25
  5. # 3kHz 10% duty cycle -> 30microseconds on, 300 microseconds off
  6.  
  7. # If accuracy problems, /boot/config.txt dtparam=audio=off
  8.  
  9. #set -x
  10.  
  11. G="$1"
  12. freq="$2"
  13. duty="$3"
  14.  
  15. usage() {
  16. echo "$0 GPIO freq duty"
  17. exit 1
  18. }
  19.  
  20. [ $G ] || usage
  21. [ $freq ] || usage
  22. [ $duty ] || usage
  23.  
  24.  
  25. period=$(python -c "print(1000000/$freq)")
  26. on=$(python -c "print(int($period *$duty/100.0))")
  27. off=$((period - on))
  28.  
  29. pigs m $G w
  30. pigs wvag $((1<<$G)) 0 $on 0 $(( 1<<$G)) $off
  31. wid=$(pigs wvcre)
  32. pigs wvtxr $wid
  33. # stop waveform by running:
  34. # pigs wvhlt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement