Install on (2) Nucleo-L053R8's with an XBee PRO 900HP on the PA_9 and PA_10 serial pins. When the user button is pressed on one of the Nucleos, the LED flashes on the other.
Dependencies: SoftSerial mbed
main.cpp@0:be753a471114, 2017-06-23 (annotated)
- Committer:
- jmckneel
- Date:
- Fri Jun 23 16:45:06 2017 +0000
- Revision:
- 0:be753a471114
0001 Enabled user button communication between two Nucleo boards
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmckneel | 0:be753a471114 | 1 | /* ----------------------------------------------------------------------------- |
jmckneel | 0:be753a471114 | 2 | Author: Jared McKneely |
jmckneel | 0:be753a471114 | 3 | Title: End-node firmware v. 1.0.0 |
jmckneel | 0:be753a471114 | 4 | Date: June 8th, 2017 |
jmckneel | 0:be753a471114 | 5 | Description: |
jmckneel | 0:be753a471114 | 6 | |
jmckneel | 0:be753a471114 | 7 | ----------------------------------------------------------------------------- */ |
jmckneel | 0:be753a471114 | 8 | |
jmckneel | 0:be753a471114 | 9 | // Libraries ------------------------------------------------------------------- |
jmckneel | 0:be753a471114 | 10 | #include "mbed.h" |
jmckneel | 0:be753a471114 | 11 | #include "SoftSerial.h" |
jmckneel | 0:be753a471114 | 12 | |
jmckneel | 0:be753a471114 | 13 | // Macros ---------------------------------------------------------------------- |
jmckneel | 0:be753a471114 | 14 | #define LED_ON (1) |
jmckneel | 0:be753a471114 | 15 | #define LED_OFF (0) |
jmckneel | 0:be753a471114 | 16 | #define TX (PB_3) |
jmckneel | 0:be753a471114 | 17 | #define RX (PA_10) |
jmckneel | 0:be753a471114 | 18 | |
jmckneel | 0:be753a471114 | 19 | // Hardware Objects ------------------------------------------------------------ |
jmckneel | 0:be753a471114 | 20 | DigitalOut led(LED1); |
jmckneel | 0:be753a471114 | 21 | InterruptIn button(USER_BUTTON); |
jmckneel | 0:be753a471114 | 22 | InterruptIn receive(PA_10); |
jmckneel | 0:be753a471114 | 23 | |
jmckneel | 0:be753a471114 | 24 | // Globals --------------------------------------------------------------------- |
jmckneel | 0:be753a471114 | 25 | SoftSerial xb(TX, RX); |
jmckneel | 0:be753a471114 | 26 | char tx = 'e'; |
jmckneel | 0:be753a471114 | 27 | char rx = '0'; |
jmckneel | 0:be753a471114 | 28 | |
jmckneel | 0:be753a471114 | 29 | // send_light ------------------------------------------------------------------ |
jmckneel | 0:be753a471114 | 30 | void send_light(void){ |
jmckneel | 0:be753a471114 | 31 | if (xb.writeable()){ |
jmckneel | 0:be753a471114 | 32 | xb.putc(tx); |
jmckneel | 0:be753a471114 | 33 | } |
jmckneel | 0:be753a471114 | 34 | } |
jmckneel | 0:be753a471114 | 35 | |
jmckneel | 0:be753a471114 | 36 | // blink_light ----------------------------------------------------------------- |
jmckneel | 0:be753a471114 | 37 | void blink_light(void){ |
jmckneel | 0:be753a471114 | 38 | led = LED_OFF; |
jmckneel | 0:be753a471114 | 39 | led = LED_ON; |
jmckneel | 0:be753a471114 | 40 | wait(0.05); |
jmckneel | 0:be753a471114 | 41 | led = LED_OFF; |
jmckneel | 0:be753a471114 | 42 | } |
jmckneel | 0:be753a471114 | 43 | |
jmckneel | 0:be753a471114 | 44 | // rx_process ------------------------------------------------------------------ |
jmckneel | 0:be753a471114 | 45 | void rx_process(void){ |
jmckneel | 0:be753a471114 | 46 | |
jmckneel | 0:be753a471114 | 47 | } |
jmckneel | 0:be753a471114 | 48 | |
jmckneel | 0:be753a471114 | 49 | // Main ------------------------------------------------------------------------ |
jmckneel | 0:be753a471114 | 50 | int main() { |
jmckneel | 0:be753a471114 | 51 | |
jmckneel | 0:be753a471114 | 52 | // Enable interrupt |
jmckneel | 0:be753a471114 | 53 | button.rise(&send_light); |
jmckneel | 0:be753a471114 | 54 | receive.rise(&rx_process); |
jmckneel | 0:be753a471114 | 55 | |
jmckneel | 0:be753a471114 | 56 | // While loop |
jmckneel | 0:be753a471114 | 57 | while (true){ |
jmckneel | 0:be753a471114 | 58 | if (xb.readable()){ |
jmckneel | 0:be753a471114 | 59 | rx = xb.getc(); |
jmckneel | 0:be753a471114 | 60 | if (rx == 'e'){ |
jmckneel | 0:be753a471114 | 61 | blink_light(); |
jmckneel | 0:be753a471114 | 62 | rx = '0'; |
jmckneel | 0:be753a471114 | 63 | } |
jmckneel | 0:be753a471114 | 64 | } |
jmckneel | 0:be753a471114 | 65 | wait(0.1); |
jmckneel | 0:be753a471114 | 66 | } |
jmckneel | 0:be753a471114 | 67 | } |