Dheeraj Kamath
/
BlinkyUart
Toggles LED and prints debug information
main.cpp@3:a773d045cb0d, 2019-05-26 (annotated)
- Committer:
- Dheeraj22
- Date:
- Sun May 26 17:20:23 2019 +0000
- Revision:
- 3:a773d045cb0d
- Parent:
- 2:e83554ed7b87
Baud rate changed to 9600.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Dheeraj22 | 0:19ea743b1bfa | 1 | /* mbed Microcontroller Library |
Dheeraj22 | 0:19ea743b1bfa | 2 | * Copyright (c) 2018 ARM Limited |
Dheeraj22 | 0:19ea743b1bfa | 3 | * SPDX-License-Identifier: Apache-2.0 |
Dheeraj22 | 0:19ea743b1bfa | 4 | */ |
Dheeraj22 | 0:19ea743b1bfa | 5 | |
Dheeraj22 | 0:19ea743b1bfa | 6 | #include "mbed.h" |
Dheeraj22 | 0:19ea743b1bfa | 7 | |
Dheeraj22 | 0:19ea743b1bfa | 8 | DigitalOut led1(LED1); |
Dheeraj22 | 2:e83554ed7b87 | 9 | RawSerial my_uart(UART_TX, UART_RX); |
Dheeraj22 | 0:19ea743b1bfa | 10 | |
Dheeraj22 | 0:19ea743b1bfa | 11 | #define SLEEP_TIME 500 // (msec) |
Dheeraj22 | 0:19ea743b1bfa | 12 | |
Dheeraj22 | 0:19ea743b1bfa | 13 | // main() runs in its own thread in the OS |
Dheeraj22 | 0:19ea743b1bfa | 14 | int main() |
Dheeraj22 | 2:e83554ed7b87 | 15 | { |
Dheeraj22 | 2:e83554ed7b87 | 16 | //Change Baud Rate |
Dheeraj22 | 3:a773d045cb0d | 17 | my_uart.baud(9600); |
Dheeraj22 | 2:e83554ed7b87 | 18 | my_uart.printf("%s\n\r", "UART Initialized"); |
Dheeraj22 | 2:e83554ed7b87 | 19 | char* msg = "OFF"; |
Dheeraj22 | 2:e83554ed7b87 | 20 | |
Dheeraj22 | 0:19ea743b1bfa | 21 | while (true) { |
Dheeraj22 | 0:19ea743b1bfa | 22 | // Blink LED and wait 0.5 seconds |
Dheeraj22 | 0:19ea743b1bfa | 23 | led1 = !led1; |
Dheeraj22 | 2:e83554ed7b87 | 24 | led1 ? (msg = "OFF"):(msg = "ON"); |
Dheeraj22 | 2:e83554ed7b87 | 25 | my_uart.printf("LED STATE: %s\n\r", msg); |
Dheeraj22 | 0:19ea743b1bfa | 26 | wait_ms(SLEEP_TIME); |
Dheeraj22 | 0:19ea743b1bfa | 27 | } |
Dheeraj22 | 0:19ea743b1bfa | 28 | } |