mirror of
https://github.com/sipeed/Maixduino.git
synced 2026-03-03 09:04:00 +01:00
43 lines
763 B
C++
43 lines
763 B
C++
#include <Arduino.h>
|
|
#include <Ticker.h>
|
|
|
|
// attach a LED to pPIO 13
|
|
#define LED_PIN 13
|
|
|
|
Ticker blinker(TIMER0);
|
|
Ticker toggler(TIMER1);
|
|
Ticker changer(TIMER2);
|
|
float blinkerPace = 0.1; //seconds
|
|
const float togglePeriod = 5; //seconds
|
|
|
|
void change() {
|
|
blinkerPace = 0.5;
|
|
}
|
|
|
|
void blink() {
|
|
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
|
|
}
|
|
|
|
void toggle() {
|
|
static bool isBlinking = false;
|
|
if (isBlinking) {
|
|
blinker.detach();
|
|
isBlinking = false;
|
|
}
|
|
else {
|
|
blinker.attach(blinkerPace, blink);
|
|
isBlinking = true;
|
|
}
|
|
digitalWrite(LED_PIN, LOW); //make sure LED on on after toggling (pin LOW = led ON)
|
|
}
|
|
|
|
void setup() {
|
|
pinMode(LED_PIN, OUTPUT);
|
|
toggler.attach(togglePeriod, toggle);
|
|
changer.once(30, change);
|
|
}
|
|
|
|
void loop() {
|
|
|
|
}
|