Cicero Matos
/
Serial_Comm_1
Serial comm (over USB) from mbed example, and formated serial display on Realterm terminal
main.cpp@0:2ca76d3b571d, 2013-12-26 (annotated)
- Committer:
- strain11
- Date:
- Thu Dec 26 04:26:21 2013 +0000
- Revision:
- 0:2ca76d3b571d
Serial Comm first project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
strain11 | 0:2ca76d3b571d | 1 | #include "mbed.h" |
strain11 | 0:2ca76d3b571d | 2 | //====================================================================================== |
strain11 | 0:2ca76d3b571d | 3 | Serial pc(USBTX, USBRX); // tx, rx |
strain11 | 0:2ca76d3b571d | 4 | PwmOut led(LED1); |
strain11 | 0:2ca76d3b571d | 5 | DigitalOut myled_4(LED4); |
strain11 | 0:2ca76d3b571d | 6 | //====================================================================================== |
strain11 | 0:2ca76d3b571d | 7 | |
strain11 | 0:2ca76d3b571d | 8 | |
strain11 | 0:2ca76d3b571d | 9 | float brightness = 0.0; |
strain11 | 0:2ca76d3b571d | 10 | |
strain11 | 0:2ca76d3b571d | 11 | |
strain11 | 0:2ca76d3b571d | 12 | int main() { |
strain11 | 0:2ca76d3b571d | 13 | pc.printf("*************************************************\n"); |
strain11 | 0:2ca76d3b571d | 14 | pc.printf("PROGRAMA DE TESTE DA COMUNICACAO SERIAL\n"); |
strain11 | 0:2ca76d3b571d | 15 | //wait(1.5); |
strain11 | 0:2ca76d3b571d | 16 | pc.printf("25-12-2013 - VERSAO 00\n"); |
strain11 | 0:2ca76d3b571d | 17 | //wait(1.5); |
strain11 | 0:2ca76d3b571d | 18 | pc.printf("PROGRAMA REALTERM 20070 NO LADO DO PC\n"); |
strain11 | 0:2ca76d3b571d | 19 | //wait(1.5); |
strain11 | 0:2ca76d3b571d | 20 | pc.printf(" \n"); |
strain11 | 0:2ca76d3b571d | 21 | pc.printf("PRESSSIONE 'u' PARA AUMENTAR O BRILHO DO LED_1\n"); |
strain11 | 0:2ca76d3b571d | 22 | pc.printf(" \n"); |
strain11 | 0:2ca76d3b571d | 23 | pc.printf("PRESSSIONE 'd' PARA DIMINUIR O BRILHO DO LED_1\n"); |
strain11 | 0:2ca76d3b571d | 24 | pc.printf(" \n"); |
strain11 | 0:2ca76d3b571d | 25 | pc.printf("BRILHO ="); |
strain11 | 0:2ca76d3b571d | 26 | |
strain11 | 0:2ca76d3b571d | 27 | pc.printf("%f", brightness); |
strain11 | 0:2ca76d3b571d | 28 | pc.printf(" \n"); |
strain11 | 0:2ca76d3b571d | 29 | pc.printf("*************************************************\n"); |
strain11 | 0:2ca76d3b571d | 30 | |
strain11 | 0:2ca76d3b571d | 31 | //==================================================================================== |
strain11 | 0:2ca76d3b571d | 32 | while(1) { |
strain11 | 0:2ca76d3b571d | 33 | char c = pc.getc(); |
strain11 | 0:2ca76d3b571d | 34 | if((c == 'u') && (brightness < 0.5)) { |
strain11 | 0:2ca76d3b571d | 35 | brightness += 0.01; |
strain11 | 0:2ca76d3b571d | 36 | led = brightness; |
strain11 | 0:2ca76d3b571d | 37 | pc.printf("VALOR AUMENTADO DE +0,01\n"); |
strain11 | 0:2ca76d3b571d | 38 | |
strain11 | 0:2ca76d3b571d | 39 | } |
strain11 | 0:2ca76d3b571d | 40 | |
strain11 | 0:2ca76d3b571d | 41 | |
strain11 | 0:2ca76d3b571d | 42 | if((c == 'd') && (brightness > 0.0)) { |
strain11 | 0:2ca76d3b571d | 43 | brightness -= 0.01; |
strain11 | 0:2ca76d3b571d | 44 | led = brightness; |
strain11 | 0:2ca76d3b571d | 45 | pc.printf("VALOR DIMINUIDO DE -0,01\n"); |
strain11 | 0:2ca76d3b571d | 46 | |
strain11 | 0:2ca76d3b571d | 47 | } |
strain11 | 0:2ca76d3b571d | 48 | //-------------------------------------------------------------------------- |
strain11 | 0:2ca76d3b571d | 49 | if((c == '1')) { |
strain11 | 0:2ca76d3b571d | 50 | myled_4= 1; |
strain11 | 0:2ca76d3b571d | 51 | pc.printf("LED_4 LIGADO\n"); |
strain11 | 0:2ca76d3b571d | 52 | pc.printf("------------\n"); |
strain11 | 0:2ca76d3b571d | 53 | goto saida; |
strain11 | 0:2ca76d3b571d | 54 | } |
strain11 | 0:2ca76d3b571d | 55 | //------------------------------------------------------------------------- |
strain11 | 0:2ca76d3b571d | 56 | if((c == '0')) { |
strain11 | 0:2ca76d3b571d | 57 | myled_4= 0; |
strain11 | 0:2ca76d3b571d | 58 | pc.printf("LED_4 DESLIGADO\n"); |
strain11 | 0:2ca76d3b571d | 59 | pc.printf("---------------\n"); |
strain11 | 0:2ca76d3b571d | 60 | goto saida; |
strain11 | 0:2ca76d3b571d | 61 | } |
strain11 | 0:2ca76d3b571d | 62 | //------------------------------------------------------------------------- |
strain11 | 0:2ca76d3b571d | 63 | pc.printf("BRILHO = "); |
strain11 | 0:2ca76d3b571d | 64 | pc.printf("%f", brightness); |
strain11 | 0:2ca76d3b571d | 65 | pc.printf(" \n"); |
strain11 | 0:2ca76d3b571d | 66 | pc.printf("------------------------\n"); |
strain11 | 0:2ca76d3b571d | 67 | //------------------------------------------------------------------------- |
strain11 | 0:2ca76d3b571d | 68 | saida: |
strain11 | 0:2ca76d3b571d | 69 | { |
strain11 | 0:2ca76d3b571d | 70 | pc.printf(" \n"); |
strain11 | 0:2ca76d3b571d | 71 | } |
strain11 | 0:2ca76d3b571d | 72 | } |
strain11 | 0:2ca76d3b571d | 73 | } |