LoRa node acquiring random float value and sending to LoRa Server - Working ok
Fork of SX1276GenericLib by
Arduino-mbed-APIs/examples/TimerTest/TimerTest.ino@99:0e85871f676a, 2017-11-18 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Sat Nov 18 13:55:54 2017 +0100
- Revision:
- 99:0e85871f676a
- Parent:
- 75:7330dd86cdea
- Child:
- 100:c80d1416bdf6
Added correct support for ESP32 Serial, ESP32 ports
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 | 72:2a6c776b5e92 | 32 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 33 | tp.attach(callback(&TestTimeoutFunc), 1000); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 34 | tp2.attach(callback(&TestTimeoutFunc55), 5500); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 35 | tp3.attach(callback(&TestTimeoutFunc10), 10000); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 36 | // tp4.attach(callback(&TestTimeoutFunc1m), 1); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 37 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 38 | intr.mode(PullUp); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 39 | intr.fall(callback(&SwitchInput)); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 40 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 41 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 42 | void loop() { |
Helmut Tschemernjak | 99:0e85871f676a | 43 | // led = !led; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 44 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 45 | sleep(); // or deepsleep() |
Helmut Tschemernjak | 72:2a6c776b5e92 | 46 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 47 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 48 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 49 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 50 | void TestTimeoutFunc(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 51 | tp.attach(callback(&TestTimeoutFunc), 1000); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 52 | led = !led; |
Helmut Tschemernjak | 75:7330dd86cdea | 53 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 54 | ser->println(" TestTimeoutFunc 1 sec"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 55 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 56 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 57 | void TestTimeoutFunc55(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 58 | tp2.attach(callback(&TestTimeoutFunc55), 5500); |
Helmut Tschemernjak | 75:7330dd86cdea | 59 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 60 | ser->println(" TestTimeoutFunc 5.5 sec"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 61 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 62 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 63 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 64 | void TestTimeoutFunc10(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 65 | tp3.attach(callback(&TestTimeoutFunc10), 10000); |
Helmut Tschemernjak | 75:7330dd86cdea | 66 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 67 | ser->println(" TestTimeoutFunc 10 sec"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 68 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 69 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 70 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 71 | void TestTimeoutFunc1m(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 72 | tp4.attach(callback(&TestTimeoutFunc1m), 1); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 73 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 74 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 75 | void SwitchInput(void) { |
Helmut Tschemernjak | 75:7330dd86cdea | 76 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 77 | ser->println(" SwitchInput"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 78 | led = !led; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 79 | } |