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.
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 TextLCD lcd(D8, D9, D4, D5, D6, D7); //rs,e,d0,d1,d2,d3 00005 AnalogIn xAxis(A0); 00006 AnalogIn yAxis(A1); 00007 Serial pc(USBTX, USBRX); 00008 CAN can1(PB_8, PB_9); 00009 00010 static char info[6]= {0x55, 0x54, 0x53, 0x52, 0x51, 0x50}; 00011 00012 int main() 00013 { 00014 CANMessage cima(5, &info[0], 8, CANData, CANStandard); 00015 CANMessage baixo(5, &info[1], 8, CANData, CANStandard); 00016 CANMessage esquerda(5, &info[2], 8, CANData, CANStandard); 00017 CANMessage direita(5, &info[3], 8, CANData, CANStandard); 00018 CANMessage parado(5, &info[4], 8, CANData, CANStandard); 00019 CANMessage ativar(5, &info[5], 8, CANData, CANStandard); 00020 00021 int x,y; 00022 lcd.locate(3,0); 00023 lcd.printf("Retrovisor"); 00024 00025 while(1) 00026 { 00027 wait(0.1); 00028 can1.write(ativar); 00029 x = xAxis.read()*1000; // float (0 -> 1) to int (0 -> 1000) 00030 y = yAxis.read()*1000; 00031 if (x < 200){ 00032 can1.write(esquerda); 00033 } 00034 if (x > 800){ 00035 can1.write(direita); 00036 } 00037 if (y < 200){ 00038 can1.write(baixo); 00039 } 00040 if (y > 800){ 00041 can1.write(cima); 00042 } 00043 if (x > 300 && x < 700 && y > 300 && y < 700){ 00044 can1.write(parado); 00045 } 00046 00047 if(can1.read(ativar)){ 00048 if (ativar.data[0] == 0x55){ 00049 lcd.locate(5,1); 00050 lcd.printf("Cima "); 00051 pc.printf("Cima"); 00052 } 00053 if (ativar.data[0] == 0x54){ 00054 lcd.locate(5,1); 00055 lcd.printf("Baixo "); 00056 pc.printf("Baixo"); 00057 } 00058 if (ativar.data[0] == 0x53){ 00059 lcd.locate(5,1); 00060 lcd.printf("Direita "); 00061 pc.printf("Direita"); 00062 } 00063 if (ativar.data[0] == 0x52){ 00064 lcd.locate(5,1); 00065 lcd.printf("Esquerda"); 00066 pc.printf("Esquerda "); 00067 } 00068 if (ativar.data[0] == 0x51){ 00069 lcd.locate(5,1); 00070 lcd.printf("Parado "); 00071 pc.printf("Parado"); 00072 } 00073 ativar.data[0]=0; 00074 wait(0.1); 00075 } 00076 } 00077 }
Generated on Mon Aug 15 2022 12:03:14 by
1.7.2