#include <Plaquette.h>
/*************IMPORTANT CONCEPTS*********************
DigitalOut = 0 / 1
You can put values into a DigitalOut in many ways, including:
With direct commands
1) with a piping operator (>>) and 1 or 0
2) .on() or .off()
3) .toggle()
or with generators
4) with a square wave
5) with a metro
Flow Control - IF/THEN
IF/THEN is a powerful method for structuring your code and doing
interesting things based on True/False rules.
IF statements evaluate if a condition is TRUE in the brackets, and ONLY
execute the code within its curly brackets if the statement is true. If the
statement is false, the code within the brackets is skipped over.
In this language, 1 = TRUE and 0 = FALSE.
As such,
IF (1) { this code will always execute}
IF (0) { this code will never execute }
You can query the system to ask for many object's status in order to establish
rules. You can use the objects as traditional objects, or you can also use
the object itself as a signal.
object-based approach: IF(redLed.isOn())
signal-based approach: IF(redLed)
One common danger with IF statements is sometimes people will accidentally perform
assignment operators rather than query operators inside the brackets. For example:
IF (redLed.on()) {this doesn't evaluate status, this turns the led on, and
furthermore, the statement will always be true}
GENERATORS are things like wave patterns and metros that can be treated as
signal sources that you can flow directly into Output objects.
Squarewave is better for generating CONTINUAL STATES
Metro is better for generating precise, one-time events, or bangs
*/
DigitalOut greenLed(13);
DigitalOut redLed(12);
Wave mySquareWave(SQUARE, 3.5);
Metronome myMetro(2.0);
Plotter plotter(9600); // creer un plotter avec baudrate
void step() {
// put your main code here, to run repeatedly:
// voici un maniere de controller un led
//greenLed.on();
//greenLed.off();
// voici un autre
//1 >> greenLed;
//0 >> greenLed;
// flow un squarewave dans le sortie
mySquareWave >> greenLed;
myMetro >> ;
greenLed >> plotter;
if (mySensorMetro) {
read my sensor
}
myMetro >> plotter;
/*
if(greenLed) { // if test ci le condition est "VRAI"
//si oui, le code entre les accolades est executé
redLed.off();
}
else redLed.on();
if(greenLed && redLed) { // if test ci le condition est "VRAI"
//si oui, le code entre les accolades est executé
purpleLed.off();
}
else redLed.on();
// else {
// greenLed.off();
// }
*/
}