Hi,
I am just writing a small piece of code for 5 buttons and 5 LEDs. The idea is to have the LED lightned except when a button is pushed.
This works fine :
Now, I would like to lighten the LEDs with SoftPWMSet so that I can change their intensity later.
I have tried that:
This does not work, the LEDs are off.
The part of code which shuts the LEDs off is:
As soon as it is commented, the LEDs remain at PWM value declared in setup()
I am just writing a small piece of code for 5 buttons and 5 LEDs. The idea is to have the LED lightned except when a button is pushed.
This works fine :
Code:
#include <Bounce.h>
const int NB_PADS = 5;
const int DEBOUNCE_TIME = 50;
Bounce buttons[NB_PADS] = { Bounce (0, DEBOUNCE_TIME), Bounce (1, DEBOUNCE_TIME), Bounce (2, DEBOUNCE_TIME), Bounce (3, DEBOUNCE_TIME), Bounce (4, DEBOUNCE_TIME) };
void setup() {
for (int i = 0; i < NB_PADS; i++) {
pinMode (i, INPUT_PULLUP);
}
for (int i = NB_PADS; i < NB_PADS+NB_PADS; i++) {
pinMode (i, OUTPUT);
digitalWrite(i, HIGH);
}
}
void loop() {
for (int i = 0; i < NB_PADS + 1; i++) {
buttons[i].update();
}
for (int i = 0; i < NB_PADS; i++) {
if (buttons[i].fallingEdge()) {
digitalWrite(i+NB_PADS, LOW);
}
else if (buttons[i].risingEdge()) {
if (i != 3 && i != 4) {
}
digitalWrite(i+NB_PADS, HIGH);
}
}
}
Now, I would like to lighten the LEDs with SoftPWMSet so that I can change their intensity later.
I have tried that:
Code:
#include <Bounce.h>
#include <SoftPWM.h>
const int NB_PADS = 5;
const int DEBOUNCE_TIME = 50;
const int PWM = 255;
Bounce buttons[NB_PADS] = { Bounce (0, DEBOUNCE_TIME), Bounce (1, DEBOUNCE_TIME), Bounce (2, DEBOUNCE_TIME), Bounce (3, DEBOUNCE_TIME), Bounce (4, DEBOUNCE_TIME) };
void setup() {
SoftPWMBegin();
for (int i = 0; i < NB_PADS; i++) {
pinMode (i, INPUT_PULLUP);
}
for (int i = NB_PADS; i < NB_PADS+NB_PADS; i++) {
pinMode (i, OUTPUT);
SoftPWMSet(i, PWM);
}
}
void loop() {
for (int i = 0; i < NB_PADS + 1; i++) {
buttons[i].update();
}
for (int i = 0; i < NB_PADS; i++) {
if (buttons[i].fallingEdge()) {
SoftPWMSet(i, 0);
}
else if (buttons[i].risingEdge()) {
if (i != 3 && i != 4) {
}
SoftPWMSet(i, PWM);
}
}
}
This does not work, the LEDs are off.
The part of code which shuts the LEDs off is:
Code:
for (int i = 0; i < NB_PADS + 1; i++) {
buttons[i].update();
}