You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
Arduino
48 lines
1.6 KiB
Arduino
5 years ago
|
/*
|
||
|
LED PWM
|
||
|
Uses 2 pots to control the duty cycle of a Pulse Width Modulation
|
||
5 years ago
|
with resulting values used to set both the LED and audio signal
|
||
5 years ago
|
|
||
|
<---- pot 0 ----> <---- pot 0 ---->
|
||
|
| | |
|
||
|
| | |
|
||
|
| | |
|
||
|
<-- pot 1 --> <--- ...
|
||
|
*/
|
||
|
|
||
5 years ago
|
#define LED (13)
|
||
|
#define POT_1 (0)
|
||
|
#define POT_2 (1)
|
||
|
#define SPEAKER (11)
|
||
5 years ago
|
|
||
5 years ago
|
float delay_on;
|
||
|
float delay_off;
|
||
5 years ago
|
|
||
|
void setup() {
|
||
|
// initialize the digital pin as an output.
|
||
|
// Pin 13 has an LED connected on the nano board:
|
||
5 years ago
|
pinMode(LED, OUTPUT);
|
||
|
// initialize Pin 11 as audio out
|
||
5 years ago
|
pinMode(SPEAKER, OUTPUT);
|
||
5 years ago
|
}
|
||
|
|
||
|
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
|
||
5 years ago
|
digitalWrite(LED, HIGH); // turn the LED on
|
||
5 years ago
|
digitalWrite(SPEAKER, HIGH); // set max audio signal
|
||
5 years ago
|
delay(delay_on); // wait for delay_on ms
|
||
5 years ago
|
digitalWrite(LED, LOW); // turn the LED off
|
||
5 years ago
|
digitalWrite(SPEAKER, LOW); // audio flat line
|
||
5 years ago
|
delay(delay_off); // wait for delay_off ms
|
||
5 years ago
|
}
|