translator, wb_editors
4444
правки
Matveevrj (обсуждение | вклад) (Новая страница: «beeper.beep(0.5, 2) </syntaxhighlight> All sysfs interface settings are supported (recalculation must be done manually; see section on recalculation).») |
Matveevrj (обсуждение | вклад) (Новая страница: «300px|thumb|right| Buzzer control In the web interface of the controller, buzzer control is available in the ''"Devices"'' tab. Parameter ''"Frequency"'' - sound frequency in Hz. ''"Volume"'' - volume (in conventional units, linear scale). The settings are saved when the controller is rebooted.») |
||
Строка 76: | Строка 76: | ||
===Working from sysfs=== | ===Working from sysfs=== | ||
< | To work with pwm through sysfs you need: | ||
Enable PWM output | #Export port <syntaxhighlight lang="bash">echo 0 > /sys/class/pwm/pwmchip0/export</syntaxhighlight>After that, the /sys/class/pwm/pwmchip0/pwm0 directory appears | ||
< | # Write the pwm period in nanoseconds <syntaxhighlight lang="bash">echo 250000 > /sys/class/pwm/pwmchip0/pwm0/period # set the period to 250,000 ns, i.e. in 250µs, which corresponds to a frequency of 4kHz</syntaxhighlight> | ||
echo 1 > /sys/class/pwm/pwmchip0/ | #Record volume (calculated from duty-cycle) <syntaxhighlight lang="bash">echo 125000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle # maximum volume is reached when duty_cycle = period / 2 => set duty_cycle to 125,000 ns</syntaxhighlight> | ||
#Enable PWM output <syntaxhighlight lang="bash">echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable</syntaxhighlight> | |||
</ | |||
< | To turn off the buzzer, write 0: <syntaxhighlight lang="bash">echo 0 > /sys/class/pwm/pwmchip0/pwm0/enable</syntaxhighlight> | ||
echo 0 > /sys/class/pwm/pwmchip0/ | |||
</ | |||
[https://github.com/contactless/wirenboard/tree/master/examples/beeper '''An example of a bash script for working with pwm'''] | |||
[https://github.com/contactless/wirenboard/tree/master/examples/beeper ''' | |||
Set the period in nanoseconds. The conversion from frequency (in kilohertz) to period (in nanoseconds) is performed using the formula: | |||
<b> | <b> | ||
T(ns) = 1 000 000 / f(kHz) | T(ns) = 1,000,000 / f(kHz) | ||
</b> | </b> |