#include <Plaquette.h>
DigitalOut pinkLED(9);
DigitalOut blueLED(8);
DigitalOut greenLED(10);
DigitalIn pulldownButton(2);
DigitalIn pullupButton(3, INVERTED);
DigitalIn internalpullupButton(4, INTERNAL_PULLUP);
void begin() {
// put your setup code here, to run once:
internalpullupButton.debounce();
}
void step() {
/* There are many ways to put values into a LED with a button. Here are three different strategies.
*/
//////////////////////////strategy 1: if/else statement///////////////////////////
if (pulldownButton)
pinkLED.on();
else
pinkLED.off();
////////////////////strategy 2: piping operator/////////////////////////////////////
//sending 0 to a led turns it "off" and sending a 1 turns it "on"
pullupButton >> blueLED; //you can treat DigitalIn like a boolean variable!
///////////////////strategy 3: if signal goes HIGH or LOW....////////////////////////
//if the signal moves from LOW to HIGH, send ONE command, only when change occurs.
if (internalpullupButton.rose()) greenLED.toggle();
println(internalpullupButton);
//you can use the same logic for if the signal moves from HIGH to LOW with .fell();
//or you can react to change! with .changed()
}1. Button with pull-down resistor DigitalIn pulldownButton(2);
2. Button with pull-up resistor DigitalIn pullupButton(3, INVERTED);
3. Button with internal pull-up resistors DigitalIn ipullupButtonl(4, INTERNAL_PULLUP);
1.
2.
3.