
eletronica embarcada
Revision 0:9904aeb823e9, committed 2020-06-19
- Comitter:
- robertof3
- Date:
- Fri Jun 19 20:21:44 2020 +0000
- Commit message:
- proj eletronica 19/06/2020
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Fri Jun 19 20:21:44 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jun 19 20:21:44 2020 +0000 @@ -0,0 +1,185 @@ +//------------------------------------------------------------------- +// Projeto 2020-06-15_APS3 +// Arquivo: main.cpp +// descrição: Programa APS3 - OBD +// autor: Roberto +//------------------------------------------------------------------ + +#include "mbed.h" +#include <TextLCD.h> + +Serial pc(USBTX, USBRX); // tx, rx +Serial sparkfun(PB_9, PB_8); // tx, rx + +TextLCD lcd(D8, D9, D4, D5, D6, D7); +DigitalOut LCD(LED1); + +char resposta[20]; //com folga e carater vazio +int i = 0; +int y = 0; +char bat[3]; +char rpm[4]; // 4 bytes finais +int resposta_bat; +int resposta_rpm; + +int resposta_temp; +char vel[2]; // 2 bytes finais +int resposta_vel; + +void bateria() { + + i = 0; + + memset(resposta,NULL,20); + + pc.printf("atrv \r"); // valor bat + + + while(pc.readable() == 0) { //trocar para sparkfun + } + + while(resposta[i-1] != '\r') { // ' caracter com caracter + + resposta[i] = pc.getc(); + i ++; + } + + lcd.locate (0,0); + lcd.printf("B"); + + lcd.locate (2,0); + lcd.printf(resposta); + + lcd.locate (7,0); + lcd.printf(" "); + + pc.printf(resposta); + pc.printf("\r"); + } + +void rotacao() { + + i = 0; + + memset(resposta,NULL,20); + + pc.printf("010c\r"); // valor rpm + + while(pc.readable() == 0) { //trocar para sparkfun + } + + while(resposta[i-1] != '\r') { // ' caracter com caracter + + resposta[i] = pc.getc(); + i ++; + } + + rpm[0] = resposta[i-6]; + rpm[1] = resposta[i-5]; + rpm[2] = resposta[i-3]; + rpm[3] = resposta[i-2]; // \r conta como um caracter e i conta um a mais (ofset =2) + + resposta_rpm = strtol(rpm,NULL,16)/4; //string to int em decimal| nao precisa da logica e A e B pq os bytes estao conjuntos + + lcd.locate (8,0); + lcd.printf("RPM %d",resposta_rpm); + + pc.printf(" RPM: %d \r ",resposta_rpm); + } + +void temperatura() { + + i = 0; + resposta_temp = 0; + + memset(resposta,NULL,20); + + pc.printf("0105\r"); // valor temp + + while(pc.readable() == 0) { //trocar para sparkfun + } + + while(resposta[i-1] != '\r') { // ' caracter com caracter + + resposta[i] = pc.getc(); + //pc.putc(resposta[i]); + i ++; + } + + char temp[2]; // 2 bytes finais + //memset(temp,NULL,2); + + temp[0] = resposta[i-3]; + temp[1] = resposta[i-2]; // \r conta como um caracter e i conta um a mais (ofset =2) + + pc.printf(" TEMP: %c%c \r ",temp[0], temp[1]); + + resposta_temp = strtol(temp,NULL,16)-40 ; //string to int | nao precisa da logica e A e B pq os bytes estao conjuntos + + //resposta_temp = resposta_temp - 40; + + lcd.locate (0,1); + lcd.printf("TEMP %d",resposta_temp); + + pc.printf(" TEMP: %d \r ",resposta_temp); + } + +void velocidade(){ + + i = 0; + + memset(resposta,NULL,20); + + pc.printf("010D\r"); // valor vel + + while(pc.readable() == 0) { //trocar para sparkfun + } + + while(resposta[i-1] != '\r') { // ' caracter com caracter + + resposta[i] = pc.getc(); + //pc.putc(resposta[i]); + i ++; + } + + vel[0] = resposta[i-3]; + vel[1] = resposta[i-2]; // \r conta como um caracter e i conta um a mais (ofset =2) + + resposta_vel = strtol(vel,NULL,16); //string to int | nao precisa da logica e A e B pq os bytes estao conjuntos + + lcd.locate (8,1); + lcd.printf("VEL %d",resposta_vel); + + pc.printf(" VEL %d \r ",resposta_vel); + } + +int main() { + + while(y != 10){ + + bateria(); + + wait(1); + + rotacao(); + + wait(1); + + temperatura(); + + wait(1); + + velocidade(); + + wait(1); + + ++y; + } +} + + + + + + + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Jun 19 20:21:44 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file