From c47648ad4d28b89ed1350e0356ec1ccae69bd7a7 Mon Sep 17 00:00:00 2001 From: ugrnm Date: Sat, 21 Sep 2019 16:42:25 +0200 Subject: [PATCH] simple-pwm-led --- examples/simple-pwm-led/.gitignore | 1 + examples/simple-pwm-led/Makefile | 12 +++++++++ examples/simple-pwm-led/README | 14 ++++++++++ examples/simple-pwm-led/pwm-led.ino | 41 +++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 examples/simple-pwm-led/.gitignore create mode 100644 examples/simple-pwm-led/Makefile create mode 100644 examples/simple-pwm-led/README create mode 100644 examples/simple-pwm-led/pwm-led.ino diff --git a/examples/simple-pwm-led/.gitignore b/examples/simple-pwm-led/.gitignore new file mode 100644 index 0000000..dd07bff --- /dev/null +++ b/examples/simple-pwm-led/.gitignore @@ -0,0 +1 @@ +build-* diff --git a/examples/simple-pwm-led/Makefile b/examples/simple-pwm-led/Makefile new file mode 100644 index 0000000..c8d16b0 --- /dev/null +++ b/examples/simple-pwm-led/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/README b/examples/simple-pwm-led/README new file mode 100644 index 0000000..3ff862e --- /dev/null +++ b/examples/simple-pwm-led/README @@ -0,0 +1,14 @@ +This is a bare Makefile project sample to work with ino files, and makes use +of the arduino-make/arduino-mk Makefile framework that aims to provide all of +the IDE functionalities but via a Makefile. + +See https://github.com/sudar/Arduino-Makefile + +Once installed you need to set at least these two env variables to be able to +use the Makefile: + + export ARDUINO_DIR=/usr/share/arduino + export ARDMK_DIR=/usr/share/arduino + +Adjust to reflect your own paths! Put that in your shell rc! + diff --git a/examples/simple-pwm-led/pwm-led.ino b/examples/simple-pwm-led/pwm-led.ino new file mode 100644 index 0000000..2ff0ab0 --- /dev/null +++ b/examples/simple-pwm-led/pwm-led.ino @@ -0,0 +1,41 @@ +/* + LED PWM + Uses 2 pots to control the duty cycle of a Pulse Width Modulation + + <---- pot 0 ----> <---- pot 0 ----> + | | | + | | | + | | | + <-- pot 1 --> <--- ... +*/ + +#define LED (13) +#define POT_1 (0) +#define POT_2 (1) + +int delay_on; +int delay_off; + +void setup() { + // initialize the digital pin as an output. + // Pin 13 has an LED connected on the nano board: + pinMode(LED, OUTPUT); +} + +void loop() { + // We read the value of the pots at the beginning of the loop + // and store them as integer variables (declared at the top) + //delay_on = analogRead(POT_1); + //delay_off = analogRead(POT_2); + // + // But in meergranen PCB 1.0, the pots are wired the wrong way + // So we need to adjust that :) + delay_on = 1023 - analogRead(POT_1); + delay_off = 1023 - analogRead(POT_2); + + // Parameters for the PWM + digitalWrite(LED, HIGH); // turn the LED on + delay(delay_on); // wait for delay_on ms + digitalWrite(LED, LOW); // turn the LED off + delay(delay_off); // wait for delay_off ms +}