simple-pwm-led

master
ugrnm 5 years ago
parent 5d6d21787d
commit c47648ad4d

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

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

@ -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
}
Loading…
Cancel
Save