Skip to content

Commit

Permalink
Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dok-net committed Jan 20, 2020
1 parent be033c1 commit cc71ffd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
32 changes: 16 additions & 16 deletions libraries/Ticker/examples/TickerBasic/TickerBasic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ Ticker flipper;
int count = 0;

void flip() {
int state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin
digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state

++count;
// when the counter reaches a certain value, start blinking like crazy
if (count == 20) {
flipper.attach(0.1, flip);
}
// when the counter reaches yet another value, stop blinking
else if (count == 120) {
flipper.detach();
}
int state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin
digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state

++count;
// when the counter reaches a certain value, start blinking like crazy
if (count == 20) {
flipper.attach(0.1, flip);
}
// when the counter reaches yet another value, stop blinking
else if (count == 120) {
flipper.detach();
}
}

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);

// flip the pin every 0.3s
flipper.attach(0.3, flip);
// flip the pin every 0.3s
flipper.attach(0.3, flip);
}

void loop() {
Expand Down
27 changes: 19 additions & 8 deletions libraries/Ticker/examples/TickerParameter/TickerParameter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,37 @@
#define LED_BUILTIN 13
#endif

Ticker tickerSetHigh;
Ticker tickerSetLow;
Ticker tickerSetHigh;
Ticker tickerSetChar;

void setPinLow() {
digitalWrite(LED_BUILTIN, 0);
}

void setPinHigh() {
digitalWrite(LED_BUILTIN, 1);
}

void setPin(int state) {
digitalWrite(LED_BUILTIN, state);
digitalWrite(LED_BUILTIN, state);
}

void setPinChar(char state) {
digitalWrite(LED_BUILTIN, state);
digitalWrite(LED_BUILTIN, state);
}

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);

// every 25 ms, call setPin(0)
tickerSetLow.attach_ms(25, setPin, 0);
// every 25 ms, call setPinLow()
tickerSetLow.attach_ms(25, setPinLow);

// every 26 ms, call setPinChar(1)
tickerSetHigh.attach_ms(26, setPinChar, (char)1);
// every 26 ms, call setPinHigh()
tickerSetHigh.attach_ms(26, setPinHigh);

// every 54 ms, call setPinChar(1)
tickerSetChar.attach_ms(26, setPinChar, (char)1);
}

void loop() {
Expand Down

0 comments on commit cc71ffd

Please sign in to comment.