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.
Diff: main.cpp
- Revision:
- 6:9aeb18bebe85
- Parent:
- 5:7a63cb7ec666
- Child:
- 7:278339a9eeba
--- a/main.cpp Fri Dec 06 14:29:16 2019 +0000 +++ b/main.cpp Fri Dec 13 16:06:03 2019 +0000 @@ -3,21 +3,26 @@ Serial USB_link(USBTX, USBRX); // USB initialization -PwmOut LED(A2); // LED initialization +//PwmOut LED(A2); // LED initialization glibr capt1(D4,D5); // I²C initialization : D4 = SDA ; D5 = SCL -//CAN can1(D0, D1); // CAN initialization +CAN can1(PA_11, PA_12); // CAN initialization + +CANMessage msg; bool initialization(void) { // USB initialization USB_link.baud(115200); - USB_link.format(8, SerialBase::None, 1); + USB_link.printf("Debut prog\r\n"); + + // CAN init + can1.frequency(1000000); // LED initialization - LED.period_ms(10); - LED.write(0.5); + // LED.period_ms(10); + // LED.write(0.5); // sensor initalization if( (capt1.ginit()) && (capt1.enableLightSensor(true)) && (capt1.enableProximitySensor(true)) ) { @@ -29,32 +34,39 @@ int main (void) { + uint16_t r,g,b; + uint8_t a ; char color; - uint16_t r,g,b; - uint8_t a; + if (initialization()) USB_link.printf("Initialization complete \r\n"); else USB_link.printf("Error during initialization\r\n"); - + while(1) { capt1.readRedLight(r); capt1.readGreenLight(g); capt1.readBlueLight(b); capt1.readProximity(a); - + //display of red, green and proximty variables - USB_link.printf("r: %hu g : %hu prox : %hu \r\n ",r,g,a); + //USB_link.printf("r: %hu g : %hu prox : %hu \r\n ",r,g,a); - if (a<100) { + if (a<200) { color = 0 ; // 0 means no object being measured } else if (r > g ) { color = 1 ; // 1 means red - } else if (g > r ) { + } else { color = 2 ; // 2 means green } - //can1.write(CANMessage(1200,&color,1)); - - // USB_link.printf("color : %c", color); + //USB_link.printf("color : %hu \r\n", color); + + // read of the CAN + if (can1.read(msg)) { + // verification of the ID ( 0x4B0 ) + if (msg.id==1200) { + can1.write(CANMessage(1200,&color,1)); // writing of the color value on the CAN bus + } + } + } - return 0; } \ No newline at end of file