From 916621d0d698a375425b1aeeb862d596afddf1a6 Mon Sep 17 00:00:00 2001 From: ugrnm Date: Sat, 21 Sep 2019 17:40:05 +0200 Subject: [PATCH] simple-pwm-led-audio broken --- examples/simple-pwm-led-audio/.gitignore | 1 + examples/simple-pwm-led-audio/Makefile | 12 ++++++++ .../pwm-led-audio.ino} | 30 ++++++++++++++----- 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 examples/simple-pwm-led-audio/.gitignore create mode 100644 examples/simple-pwm-led-audio/Makefile rename examples/{simple-pwm-led/pwm-led.ino => simple-pwm-led-audio/pwm-led-audio.ino} (58%) diff --git a/examples/simple-pwm-led-audio/.gitignore b/examples/simple-pwm-led-audio/.gitignore new file mode 100644 index 0000000..dd07bff --- /dev/null +++ b/examples/simple-pwm-led-audio/.gitignore @@ -0,0 +1 @@ +build-* diff --git a/examples/simple-pwm-led-audio/Makefile b/examples/simple-pwm-led-audio/Makefile new file mode 100644 index 0000000..c8d16b0 --- /dev/null +++ b/examples/simple-pwm-led-audio/Makefile @@ -0,0 +1,12 @@ +# This will only work if you have installed arduino-mk +# And set your shell rc with the following env variables: +# +# export ARDUINO_DIR=/usr/share/arduino +# export ARDMK_DIR=/usr/share/arduino +# +# Adjust to reflect your own paths! + +BOARD_TAG = nano328 +MONITOR_PORT = /dev/ttyUSB0 + +include ${ARDMK_DIR}/Arduino.mk diff --git a/examples/simple-pwm-led/pwm-led.ino b/examples/simple-pwm-led-audio/pwm-led-audio.ino similarity index 58% rename from examples/simple-pwm-led/pwm-led.ino rename to examples/simple-pwm-led-audio/pwm-led-audio.ino index 5b01adf..be4b143 100644 --- a/examples/simple-pwm-led/pwm-led.ino +++ b/examples/simple-pwm-led-audio/pwm-led-audio.ino @@ -9,17 +9,22 @@ <-- pot 1 --> <--- ... */ -#define LED (13) -#define POT_1 (0) -#define POT_2 (1) +#define LED (13) +#define POT_1 (0) +#define POT_2 (1) +#define POT_3 (2) +#define SPEAKER (11) -int delay_on; -int delay_off; +float delay_on; +float delay_off; +float delay_div; void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on the nano board: - pinMode(LED, OUTPUT); + pinMode(LED, OUTPUT); + // initialize Pin 11 as audio out + pinMode(LED, SPEAKER); } void loop() { @@ -33,9 +38,18 @@ void loop() { delay_on = 1023 - analogRead(POT_1); delay_off = 1023 - analogRead(POT_2); + // We also read pot 3 value that we will use to control a bit + // the delay to reach audible range + //delay_div = 1023 - analogRead(POT_3); + // + // But meergranen 1.0 + delay_div = analogRead(POT_3); + // Parameters for the PWM digitalWrite(LED, HIGH); // turn the LED on - delay(delay_on); // wait for delay_on ms + digitalWrite(SPEAKER, HIGH); // turn the LED on + delay(delay_on/delay_div); // wait for delay_on ms digitalWrite(LED, LOW); // turn the LED off - delay(delay_off); // wait for delay_off ms + digitalWrite(SPEAKER, LOW); // turn the LED off + delay(delay_off/delay_div); // wait for delay_off ms }