Skip to content

Commit

Permalink
Cleaned the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas O Fredericks committed Sep 27, 2017
1 parent c6e5e81 commit 5b8fe39
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions examples/blinking_2_instances/blinking_2_instances.ino
Original file line number Diff line number Diff line change
@@ -1,55 +1,46 @@
// This code will blink output 13 every 250 ms
// abd will blink output 9 every 125 ms
// This code will toggle output 13 every 250 ms
// and will toggle output 9 every 125 ms


// INCLUDE CHRONO LIBRARY : http://github.com/SofaPirate/Chrono
#include <Chrono.h>

#define LED_A 13 // Define a LED pin
#define LED_B 9 // Define another LED pin
// Create variables for the LED pins
int ledPinA = 13;
int ledPinB = 9;

// Create variables to hold the LED states
int stateA = HIGH;
int stateB = HIGH;
int ledStateA = HIGH;
int ledStateB = HIGH;

// Instantiate a Chrono object.
// Instantiate two Chronos
Chrono chronoA;

// Instantiate another metro object and set the interval to 125 milliseconds (0.125 seconds).
Chrono chronoB = Chrono();
Chrono chronoB;

void setup()
{
pinMode(LED_A,OUTPUT);
digitalWrite(LED_A,stateA);
pinMode(ledPinA,OUTPUT);
digitalWrite(ledPinA,ledStateA);

pinMode(LED_B,OUTPUT);
digitalWrite(LED_B,stateB);
pinMode(ledPinB,OUTPUT);
digitalWrite(ledPinB,ledStateB);

}

void loop()
{
// Use Chrono as a metronome with an interval of 250 ms :
// Use Chrono as a metronome with an interval of 250 ms:
if ( chronoA.hasPassed(250) ) {
chronoA.restart();
if (stateA==HIGH) {
stateA=LOW;
} else {
stateA=HIGH;
}
digitalWrite(LED_A,stateA);
chronoA.restart(); // restart the crono so that it triggers again later
ledStateA = !ledStateA; // !: toggle the state from 0 to 1 or from 1 to 0
digitalWrite(ledPinA,ledStateA);
}

// Use Chrono as a metronome with an interval of 125 ms :
// Use Chrono as a metronome with an interval of 125 ms:
if ( chronoB.hasPassed(125) ) {
chronoB.restart();
if (stateB==HIGH) {
stateB=LOW;
} else {
stateB=HIGH;
}
digitalWrite(LED_B,stateB);
chronoB.restart(); // restart the crono so that it triggers again later
ledStateB = !ledStateB; // !: toggle the state from 0 to 1 or from 1 to 0
digitalWrite(ledPinB,ledStateB);
}


Expand Down

0 comments on commit 5b8fe39

Please sign in to comment.