From 9b337de2e341be254a9c941bca719c8860144a23 Mon Sep 17 00:00:00 2001 From: El Jeffo Date: Sun, 27 Sep 2015 22:04:27 +0900 Subject: [PATCH 1/3] Fix duty cycle to half period --- wiringPi/wiringPi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 9feec9f..7e1c3a2 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -2321,7 +2321,7 @@ void pwmToneWrite (int pin, int freq) { range = 600000 / freq ; pwmSetRange (range) ; - pwmWrite (pin, freq / 2) ; + pwmWrite (pin, range / 2) ; } } From fa1628c7aa98a7d4900cad870f6aa1d4c0bda197 Mon Sep 17 00:00:00 2001 From: El Jeffo Date: Sun, 27 Sep 2015 22:33:27 +0900 Subject: [PATCH 2/3] Update frequency base to output more accurate tones --- wiringPi/wiringPi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 7e1c3a2..0f6ed22 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -2319,7 +2319,7 @@ void pwmToneWrite (int pin, int freq) pwmWrite (pin, 0) ; // Off else { - range = 600000 / freq ; + range = 200000 / freq ; pwmSetRange (range) ; pwmWrite (pin, range / 2) ; } From 095aab26fbe3cf503b260f734dc738644fdc0302 Mon Sep 17 00:00:00 2001 From: El Jeffo Date: Tue, 29 Sep 2015 10:04:00 +0000 Subject: [PATCH 3/3] Example CLI script to play tones --- build | 2 +- examples/cli_song.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) mode change 100644 => 100755 build create mode 100755 examples/cli_song.sh diff --git a/build b/build old mode 100644 new mode 100755 index 7a2126e..88662fc --- a/build +++ b/build @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # check if sudo is required and save the result as ${PFX}: [[ ${EUID} -ne 0 ]] && PFX='sudo ' || PFX='' diff --git a/examples/cli_song.sh b/examples/cli_song.sh new file mode 100755 index 0000000..4e682a5 --- /dev/null +++ b/examples/cli_song.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Example of how to export PWM Pin and play tones via CLI + +export WIRINGPI_DEBUG=true +export WIRINGPI_CODES=true +GPIO=../gpio/gpio + +$GPIO export 1 out +$GPIO mode 1 pwm +$GPIO pwmTone 1 1033 + +for i in 262 523 220 440 233 466 0 0 262 523 220 440 233 466 0 0 175 349 147 294 156 311 0 0 175 349 147 294 156 311 0 0 311 277 294 277 311 311 208 196 277 262 370 349 165 466 440 415 311 247 233 220 208 0 0 0 ; do + $GPIO pwmTone 1 $i; + sleep 0.15; +done