LoRa node acquiring random float value and sending to LoRa Server - Working ok
Fork of SX1276GenericLib by
Arduino-mbed-APIs/examples/TimerTest/TimerTest.ino@100:c80d1416bdf6, 2017-11-19 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Sun Nov 19 17:49:33 2017 +0100
- Revision:
- 100:c80d1416bdf6
- Parent:
- 99:0e85871f676a
The timer of the ESP32 does require two prints, otherwise timers
don't work. It is resolved in the ESP32-rev1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut Tschemernjak | 72:2a6c776b5e92 | 1 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 2 | #include "arduino-mbed.h" |
Helmut Tschemernjak | 72:2a6c776b5e92 | 3 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 4 | void TestTimeoutFunc(void); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 5 | void TestTimeoutFunc55(void); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 6 | void TestTimeoutFunc10(void); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 7 | void TestTimeoutFunc1m(void); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 8 | void SwitchInput(void); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 9 | |
Helmut Tschemernjak | 99:0e85871f676a | 10 | #ifdef ARDUINO_ARCH_ESP32 |
Helmut Tschemernjak | 99:0e85871f676a | 11 | #define SW0 0 |
Helmut Tschemernjak | 99:0e85871f676a | 12 | #define LED 2 |
Helmut Tschemernjak | 99:0e85871f676a | 13 | #define MYSERIAL Serial |
Helmut Tschemernjak | 99:0e85871f676a | 14 | #else |
Helmut Tschemernjak | 72:2a6c776b5e92 | 15 | #define SW0 3 // switch needs pullup |
Helmut Tschemernjak | 75:7330dd86cdea | 16 | #define LED LED_BUILTIN |
Helmut Tschemernjak | 75:7330dd86cdea | 17 | #define MYSERIAL Serial |
Helmut Tschemernjak | 99:0e85871f676a | 18 | #endif |
Helmut Tschemernjak | 72:2a6c776b5e92 | 19 | |
Helmut Tschemernjak | 75:7330dd86cdea | 20 | DigitalOut led(LED); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 21 | InterruptIn intr(SW0); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 22 | Timeout tp; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 23 | Timeout tp2; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 24 | Timeout tp3; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 25 | Timeout tp4; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 26 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 27 | void setup() { |
Helmut Tschemernjak | 75:7330dd86cdea | 28 | MYSERIAL.begin(230400); |
Helmut Tschemernjak | 99:0e85871f676a | 29 | InitSerial(&MYSERIAL, 5000, &led, true); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 30 | |
Helmut Tschemernjak | 75:7330dd86cdea | 31 | ser->println("TimerTest"); |
Helmut Tschemernjak | 100:c80d1416bdf6 | 32 | ser->println("TimerTest2"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 33 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 34 | tp.attach(callback(&TestTimeoutFunc), 1000); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 35 | tp2.attach(callback(&TestTimeoutFunc55), 5500); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 36 | tp3.attach(callback(&TestTimeoutFunc10), 10000); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 37 | // tp4.attach(callback(&TestTimeoutFunc1m), 1); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 38 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 39 | intr.mode(PullUp); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 40 | intr.fall(callback(&SwitchInput)); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 41 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 42 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 43 | void loop() { |
Helmut Tschemernjak | 99:0e85871f676a | 44 | // led = !led; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 45 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 46 | sleep(); // or deepsleep() |
Helmut Tschemernjak | 72:2a6c776b5e92 | 47 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 48 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 49 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 50 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 51 | void TestTimeoutFunc(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 52 | tp.attach(callback(&TestTimeoutFunc), 1000); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 53 | led = !led; |
Helmut Tschemernjak | 75:7330dd86cdea | 54 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 55 | ser->println(" TestTimeoutFunc 1 sec"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 56 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 57 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 58 | void TestTimeoutFunc55(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 59 | tp2.attach(callback(&TestTimeoutFunc55), 5500); |
Helmut Tschemernjak | 75:7330dd86cdea | 60 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 61 | ser->println(" TestTimeoutFunc 5.5 sec"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 62 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 63 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 64 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 65 | void TestTimeoutFunc10(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 66 | tp3.attach(callback(&TestTimeoutFunc10), 10000); |
Helmut Tschemernjak | 75:7330dd86cdea | 67 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 68 | ser->println(" TestTimeoutFunc 10 sec"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 69 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 70 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 71 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 72 | void TestTimeoutFunc1m(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 73 | tp4.attach(callback(&TestTimeoutFunc1m), 1); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 74 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 75 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 76 | void SwitchInput(void) { |
Helmut Tschemernjak | 75:7330dd86cdea | 77 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 78 | ser->println(" SwitchInput"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 79 | led = !led; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 80 | } |