ReactESP 1.0.0
Asynchronous programming for the ESP microcontrollers
main.cpp
Go to the documentation of this file.
1#include <Arduino.h>
2#include <ReactESP.h>
3
4#ifdef ESP32
5#define LED_PIN 2
6#define INPUT_PIN 13
7#define OUTPUT_PIN 15
8#elif defined(ESP8266)
9#define LED_PIN D2
10#define INPUT_PIN D5
11#define OUTPUT_PIN D4
12#endif
13
14#define IO_REPEAT_DELAY 200
15
16volatile int ticks = 0;
17
18void ICACHE_RAM_ATTR isr() { ticks++; }
19
21 Serial.begin(115200);
22
23 pinMode(LED_PIN, OUTPUT);
24 pinMode(INPUT_PIN, INPUT_PULLUP);
25
27 static bool state = false;
28 digitalWrite(LED_PIN, state);
29 state = !state;
30 });
31
32 // attachInterrupt(INPUT_PIN, &isr, FALLING);
33 app.onInterrupt(INPUT_PIN, RISING, &isr);
34
35 app.onRepeat(1000, []() {
36 uint64_t now = micros64();
37 uint32_t now_high = now >> 32;
38 uint32_t now_low = now & 0xffffffff;
39 Serial.printf("Ticks: %d %08X %08X\n", ticks, now_high, now_low);
40 ticks = 0;
41 });
42
43 pinMode(OUTPUT_PIN, OUTPUT);
44
45 app.onRepeat(20, []() {
46 digitalWrite(OUTPUT_PIN, !digitalRead(OUTPUT_PIN));
47 });
48
49 Serial.println("First");
50 Serial.println("Second");
51});
Main class of a ReactESP program.
Definition: ReactESP.h:245
ISRReaction * onInterrupt(const uint8_t pin_number, int mode, const react_callback cb)
Create a new ISRReaction (interrupt reaction)
Definition: ReactESP.cpp:182
RepeatReaction * onRepeatMicros(const uint64_t t, const react_callback cb)
Create a new RepeatReaction.
Definition: ReactESP.cpp:169
RepeatReaction * onRepeat(const uint32_t t, const react_callback cb)
Create a new RepeatReaction.
Definition: ReactESP.cpp:163
ReactESP app([]() { Serial.begin(115200);pinMode(LED_PIN, OUTPUT);pinMode(INPUT_PIN, INPUT_PULLUP);app.onRepeatMicros(IO_REPEAT_DELAY, []() { static bool state=false;digitalWrite(LED_PIN, state);state=!state;});app.onInterrupt(INPUT_PIN, RISING, &isr);app.onRepeat(1000, []() { uint64_t now=micros64();uint32_t now_high=now > > 32;uint32_t now_low=now &0xffffffff;Serial.printf("Ticks: %d %08X %08X\n", ticks, now_high, now_low);ticks=0;});pinMode(OUTPUT_PIN, OUTPUT);app.onRepeat(20, []() { digitalWrite(OUTPUT_PIN, !digitalRead(OUTPUT_PIN));});Serial.println("First");Serial.println("Second");})
void ICACHE_RAM_ATTR isr()
Definition: main.cpp:18
volatile int ticks
Definition: main.cpp:16
#define IO_REPEAT_DELAY
Definition: main.cpp:14