Skip to content

Commit 3d05915

Browse files
committed
Examples
1 parent 84daf7a commit 3d05915

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

Diff for: libraries/Ticker/examples/TickerBasic/TickerBasic.ino

+16-16
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@ Ticker flipper;
2323
int count = 0;
2424

2525
void flip() {
26-
int state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin
27-
digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state
28-
29-
++count;
30-
// when the counter reaches a certain value, start blinking like crazy
31-
if (count == 20) {
32-
flipper.attach(0.1, flip);
33-
}
34-
// when the counter reaches yet another value, stop blinking
35-
else if (count == 120) {
36-
flipper.detach();
37-
}
26+
int state = digitalRead(LED_BUILTIN); // get the current state of GPIO1 pin
27+
digitalWrite(LED_BUILTIN, !state); // set pin to the opposite state
28+
29+
++count;
30+
// when the counter reaches a certain value, start blinking like crazy
31+
if (count == 20) {
32+
flipper.attach(0.1, flip);
33+
}
34+
// when the counter reaches yet another value, stop blinking
35+
else if (count == 120) {
36+
flipper.detach();
37+
}
3838
}
3939

4040
void setup() {
41-
pinMode(LED_BUILTIN, OUTPUT);
42-
digitalWrite(LED_BUILTIN, LOW);
41+
pinMode(LED_BUILTIN, OUTPUT);
42+
digitalWrite(LED_BUILTIN, LOW);
4343

44-
// flip the pin every 0.3s
45-
flipper.attach(0.3, flip);
44+
// flip the pin every 0.3s
45+
flipper.attach(0.3, flip);
4646
}
4747

4848
void loop() {

Diff for: libraries/Ticker/examples/TickerParameter/TickerParameter.ino

+19-8
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,37 @@
1717
#define LED_BUILTIN 13
1818
#endif
1919

20-
Ticker tickerSetHigh;
2120
Ticker tickerSetLow;
21+
Ticker tickerSetHigh;
22+
Ticker tickerSetChar;
23+
24+
void setPinLow() {
25+
digitalWrite(LED_BUILTIN, 0);
26+
}
27+
28+
void setPinHigh() {
29+
digitalWrite(LED_BUILTIN, 1);
30+
}
2231

2332
void setPin(int state) {
24-
digitalWrite(LED_BUILTIN, state);
33+
digitalWrite(LED_BUILTIN, state);
2534
}
2635

2736
void setPinChar(char state) {
28-
digitalWrite(LED_BUILTIN, state);
37+
digitalWrite(LED_BUILTIN, state);
2938
}
3039

3140
void setup() {
32-
pinMode(LED_BUILTIN, OUTPUT);
41+
pinMode(LED_BUILTIN, OUTPUT);
3342

34-
// every 25 ms, call setPin(0)
35-
tickerSetLow.attach_ms(25, setPin, 0);
43+
// every 25 ms, call setPinLow()
44+
tickerSetLow.attach_ms(25, setPinLow);
3645

37-
// every 26 ms, call setPinChar(1)
38-
tickerSetHigh.attach_ms(26, setPinChar, (char)1);
46+
// every 26 ms, call setPinHigh()
47+
tickerSetHigh.attach_ms(26, setPinHigh);
3948

49+
// every 54 ms, call setPinChar(1)
50+
tickerSetChar.attach_ms(26, setPinChar, (char)1);
4051
}
4152

4253
void loop() {

0 commit comments

Comments
 (0)