Advertisement
j0h

ts7600_ADC.sh

j0h
Apr 21st, 2023
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.68 KB | None | 0 0
  1. #!/bin/bash
  2. #IO INTIIALIZATION
  3.         tshwctl --setdio=65 #System Power ON
  4.         tshwctl --clrdio=57 #red OFF
  5.         tshwctl --clrdio=59 #yellow OFF
  6.         tshwctl --clrdio=61 #Green OFF
  7.  
  8. #CTRL+C Trap_EXIT_EXEC
  9. trap ctrl_c INT
  10. #trap 'tshwctl --clrdio=65' EXIT
  11. function ctrl_c() {
  12. #TURN OFF ALL IO
  13.         tshwctl --clrdio=57
  14.         tshwctl --clrdio=59
  15.         tshwctl --clrdio=61
  16.         tshwctl --clrdio=65
  17.         echo "** PROGRAM TERMINATED **"
  18.         exit
  19. }
  20.  
  21. #MAIN Loop
  22. for i in $(seq 0 1000)
  23. do
  24. reading=$(./adc1)
  25. #echo $reading
  26.  
  27. if [ $reading -lt 300 ]
  28. then
  29.         clear
  30.         echo "System Nominal"
  31.         tshwctl --clrdio=59
  32.         tshwctl --clrdio=57
  33.         tshwctl --setdio=61 #green ON
  34.  
  35. #Compund logical expansion in BASH
  36. elif [[ $reading -gt 301 &&  $reading -lt 1000 ]];
  37. then
  38.         tshwctl --clrdio=57 #red OFF
  39.         clear
  40.         echo "Intermediate Voltage Detected"
  41.         tshwctl --setdio=59 #yellow ON
  42.         tshwctl --setdio=61 #green ON
  43.  
  44. elif [[ $reading -gt 1001 && $reading -lt 2000 ]];
  45. then
  46.         clear
  47.         echo "Median Voltage Detected"
  48.         tshwctl --clrdio=57  #red OFF
  49.         tshwctl --clrdio=61  #green OFF
  50.         tshwctl --setdio=59  #yellow ON
  51.  
  52. elif [ $reading -gt 2000  ]
  53. then
  54.         clear
  55.         echo "Alert! HIGH VOLTAGE DETECTED!"
  56.         tshwctl --clrdio=61  #green OFF
  57.         tshwctl --clrdio=59 #yellow OFF
  58.         tshwctl --setdio=57 #Red ON
  59. else
  60.         tshwctl --clrdio=61
  61.         tshwctl --clrdio=59
  62.         tshwctl --clrdio=57
  63.  
  64. fi
  65. #sleep 1
  66. done
  67. #END LOOP ALL IO IS OFF
  68.         tshwctl --clrdio=57
  69.         tshwctl --clrdio=59
  70.         tshwctl --clrdio=61
  71.         tshwctl --clrdio=65
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement