Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 107:1f8f680bc11a, committed 2020-04-02
- Comitter:
- allansolvertecnologi
- Date:
- Thu Apr 02 21:43:06 2020 +0000
- Parent:
- 106:d323dd088ba2
- Commit message:
- UART ok
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Nov 22 16:00:04 2019 +0000 +++ b/main.cpp Thu Apr 02 21:43:06 2020 +0000 @@ -1,23 +1,66 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - */ #include "mbed.h" #include "platform/mbed_thread.h" -// Blinking rate in milliseconds -#define BLINKING_RATE_MS 500 +// Configurando LEDs +DigitalOut ledGreen(D12); +DigitalOut ledRed(D11); +DigitalOut Dout(D1); + +//Configurações SPI +Serial xbee(D1, D0, 9600); //Pinos seriais (Tx/Rx) +DigitalOut rst1(D6); //Digital reset + + +char a = 'A'; + + +void xbee_send(int send) //envia byte +{ + Dout = 0; + xbee.putc(send); + Dout = 1; +} + +int xbee_receive() //Retorna byte lido ou 0 se não tiver leitura pronta +{ + if(xbee.readable()){ + int a = xbee.getc(); + } + else + a= 0; + return a; //XBee read +} int main() { - // Initialise the digital pin LED1 as an output - DigitalOut led(LED1); - - while (true) { - led = !led; - thread_sleep_for(BLINKING_RATE_MS); + rst1 = 0; //Set reset pin to 0 + Dout = 0; + ledGreen = 0; + ledRed = 0; + wait_ms(1); + rst1 = 1; //Set reset pin to 1 + wait_ms(1); // Configura como UART com 9600 de baud rate + + while (1) + { + xbee_send('+'); + xbee_send('+'); + xbee_send('+'); + //xbee_send('R'); + + ledRed = !ledRed; + while(!xbee.readable()); + if(xbee.getc() == 'O') + { + if(xbee.getc() == 'K') + ledGreen = !ledGreen; + } + + + wait_ms(2000); + } }