Shell PWM Software Fader

Phishfry

Son of Beastie

Thanks: 872
Messages: 2,756

#1
I need help making a script more useful. This is for software fading an LED.
fade-in.sh
Code:
#!/bin/sh
sysctl dev.am335x_ehrpwm.1.dutyA: 0
sysctl dev.am335x_ehrpwm.1.dutyA: 5
sysctl dev.am335x_ehrpwm.1.dutyA: 10
sysctl dev.am335x_ehrpwm.1.dutyA: 15
sysctl dev.am335x_ehrpwm.1.dutyA: 20
sysctl dev.am335x_ehrpwm.1.dutyA: 25
sysctl dev.am335x_ehrpwm.1.dutyA: 30
sysctl dev.am335x_ehrpwm.1.dutyA: 35
sysctl dev.am335x_ehrpwm.1.dutyA: 40
sysctl dev.am335x_ehrpwm.1.dutyA: 45
sysctl dev.am335x_ehrpwm.1.dutyA: 50
sysctl dev.am335x_ehrpwm.1.dutyA: 55
sysctl dev.am335x_ehrpwm.1.dutyA: 60
sysctl dev.am335x_ehrpwm.1.dutyA: 65
sysctl dev.am335x_ehrpwm.1.dutyA: 70
sysctl dev.am335x_ehrpwm.1.dutyA: 75
sysctl dev.am335x_ehrpwm.1.dutyA: 80
sysctl dev.am335x_ehrpwm.1.dutyA: 85
sysctl dev.am335x_ehrpwm.1.dutyA: 90
sysctl dev.am335x_ehrpwm.1.dutyA: 95
sysctl dev.am335x_ehrpwm.1.dutyA: 100
I would like to have a slower fade (sleep?). Maybe more increments.
If I had a better grip on C programming and sysctlbyname I am sure there is a better way.

Any suggestions appreciated.
 

ralphbsz

Daemon

Thanks: 710
Messages: 1,209

#2
Don't use C. Use a simpler, easier-to-learn language like Python or Perl or Ruby. In there, sleeping for a fraction of a second is easy.

To perform the sysctl function, don't just execute the sysctl executable command with the "system()" function in python. That would be needlessly slow, inefficient, and error-prone. Instead, there is a python library that allows direct access to sysctl.
 
Top