![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
7 jul
Dependencies: BSP_DISCO_F469NIa EEPROM_DISCO_F469NI LCD_DISCO_F469NIa SD_DISCO_F469NI mbed
Fork of IntegrationCAN_7jul by
Diff: main.cpp
- Revision:
- 3:a06e417a5a2c
- Parent:
- 2:f54f01527ebb
- Child:
- 4:0e8413277df8
--- a/main.cpp Thu Jun 28 16:33:23 2018 +0000 +++ b/main.cpp Thu Jul 05 20:18:32 2018 +0000 @@ -7,7 +7,9 @@ SD_DISCO_F469NI sd; //Initialize SD Card //EEPROM_DISCO_F469NI eep; //Initialize EEPROM Internal memory Serial pc(USBTX, USBRX); //Initialize Serial. This is used only while debuging code. -CAN can(PB_5, PB_13); //Initialize CAN. +CAN can(PB_5, PB_13,1000000); //Initialize CAN. +I2C i2c(D14, D15); +DigitalOut reset(D8); InterruptIn change_screen_input(D0); //Initialize Digital input for Change screen button Timer t_int,t_store; @@ -40,13 +42,94 @@ CANMessage msgBrakes; // Brake system preassure, Braking On/Off CANMessage msgDistance; // Total distance +// LED Bar for RPM -int main(){ +char cmd[3]; +int addr = 0x74<<1; + +void LEDInitialize(){ + reset.write(1); + wait(1); + // set port as output + cmd[0]=0x06; + cmd[1]=0x00; + cmd[2]=0x00; + i2c.write(addr,cmd,3); + pc.printf( "cao\n"); +} + +void showLedRpm(int RPM){ + pc.printf("%d\n",RPM); + if(RPM<1000) { + cmd[1]=0xFF; + cmd[2]=0xFF; + } + else if (RPM<2000) { + cmd[1]=0xFF; + cmd[2]=0xDF; + } + else if (RPM <3000) { + cmd[1]=0xFF; + cmd[2]=0xCF; + } + else if (RPM <4000) { + cmd[1]=0xFF; + cmd[2]=0xC7; + } + else if (RPM <5000) { + pc.printf("tu sam %d\n", RPM); + cmd[1]=0xFF; + cmd[2]=0xC3; + } + else if (RPM <6000) { + cmd[1]=0xFF; + cmd[2]=0xC1; + } + else if (RPM <7000) { + cmd[1]=0xFF; + cmd[2]=0xC0; + } + else if (RPM <8000) { + cmd[1]=0xBF; + cmd[2]=0xC0; + } + else if (RPM <9000) { + cmd[1]=0x9F; + cmd[2]=0xC0; + } + else if (RPM <10000) { + cmd[1]=0x8F; + cmd[2]=0xC0; + } + else if (RPM <11000) { + cmd[1]=0x87; + cmd[2]=0xC0; + } + else if (RPM <12000) { + cmd[1]=0x83; + cmd[2]=0xC0; + } + else if (RPM <13000) { + cmd[1]=0x81; + cmd[2]=0xC0; + } + else { + cmd[1]=0x80; + cmd[2]=0xC0; + } + cmd[0]=0x02; + i2c.write(addr, cmd, 3); +} + + +int main(){ + LEDInitialize(); can.attach(&CANMsgReceive,CAN::RxIrq); // Attach interrupt function to CAN RX change_screen_input.rise(&ChangeCommand); //Attach interrupt function to rising edge of DigitalIn for changing screen. SetIntro(); // Display logo when starting display SetMain(); // First screen is main by default - //sd.Init(); + sd.Init(); + while(1){ if(change_flag){ // Check if screen is changed ChangeScreen(); @@ -64,4 +147,5 @@ break; }; }; + }; \ No newline at end of file