LoRa node acquiring random float value and sending to LoRa Server - Working ok
Fork of SX1276GenericLib by
Arduino-mbed-APIs/examples/TimerTest/TimerTest.ino@75:7330dd86cdea, 2017-07-26 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Wed Jul 26 15:18:35 2017 +0200
- Revision:
- 75:7330dd86cdea
- Parent:
- 72:2a6c776b5e92
- Child:
- 99:0e85871f676a
Added a default Serial configuration which allows to switch
between Serial and SerialUSB via a single simple define.
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 | 72:2a6c776b5e92 | 10 | #define SW0 3 // switch needs pullup |
Helmut Tschemernjak | 75:7330dd86cdea | 11 | #define LED LED_BUILTIN |
Helmut Tschemernjak | 75:7330dd86cdea | 12 | #define MYSERIAL Serial |
Helmut Tschemernjak | 72:2a6c776b5e92 | 13 | |
Helmut Tschemernjak | 75:7330dd86cdea | 14 | DigitalOut led(LED); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 15 | InterruptIn intr(SW0); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 16 | Timeout tp; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 17 | Timeout tp2; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 18 | Timeout tp3; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 19 | Timeout tp4; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 20 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 21 | void setup() { |
Helmut Tschemernjak | 75:7330dd86cdea | 22 | MYSERIAL.begin(230400); |
Helmut Tschemernjak | 75:7330dd86cdea | 23 | InitSerial(&MYSERIAL); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 24 | |
Helmut Tschemernjak | 75:7330dd86cdea | 25 | ser->println("TimerTest"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 26 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 27 | tp.attach(callback(&TestTimeoutFunc), 1000); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 28 | tp2.attach(callback(&TestTimeoutFunc55), 5500); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 29 | tp3.attach(callback(&TestTimeoutFunc10), 10000); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 30 | // tp4.attach(callback(&TestTimeoutFunc1m), 1); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 31 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 32 | intr.mode(PullUp); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 33 | intr.fall(callback(&SwitchInput)); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 34 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 35 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 36 | void loop() { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 37 | led = !led; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 38 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 39 | sleep(); // or deepsleep() |
Helmut Tschemernjak | 72:2a6c776b5e92 | 40 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 41 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 42 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 43 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 44 | void TestTimeoutFunc(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 45 | tp.attach(callback(&TestTimeoutFunc), 1000); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 46 | led = !led; |
Helmut Tschemernjak | 75:7330dd86cdea | 47 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 48 | ser->println(" TestTimeoutFunc 1 sec"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 49 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 50 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 51 | void TestTimeoutFunc55(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 52 | tp2.attach(callback(&TestTimeoutFunc55), 5500); |
Helmut Tschemernjak | 75:7330dd86cdea | 53 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 54 | ser->println(" TestTimeoutFunc 5.5 sec"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 55 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 56 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 57 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 58 | void TestTimeoutFunc10(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 59 | tp3.attach(callback(&TestTimeoutFunc10), 10000); |
Helmut Tschemernjak | 75:7330dd86cdea | 60 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 61 | ser->println(" TestTimeoutFunc 10 sec"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 62 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 63 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 64 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 65 | void TestTimeoutFunc1m(void) { |
Helmut Tschemernjak | 72:2a6c776b5e92 | 66 | tp4.attach(callback(&TestTimeoutFunc1m), 1); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 67 | } |
Helmut Tschemernjak | 72:2a6c776b5e92 | 68 | |
Helmut Tschemernjak | 72:2a6c776b5e92 | 69 | void SwitchInput(void) { |
Helmut Tschemernjak | 75:7330dd86cdea | 70 | ser->print(ms_getTicker(), DEC); |
Helmut Tschemernjak | 75:7330dd86cdea | 71 | ser->println(" SwitchInput"); |
Helmut Tschemernjak | 72:2a6c776b5e92 | 72 | led = !led; |
Helmut Tschemernjak | 72:2a6c776b5e92 | 73 | } |