simple-pwm-led-audio broken

master
ugrnm 5 years ago
parent 9e982b41cf
commit 916621d0d6

@ -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

@ -12,14 +12,19 @@
#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);
// 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
}
Loading…
Cancel
Save