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
- Committer:
- guilhemMBED
- Date:
- 2019-12-13
- Revision:
- 6:9aeb18bebe85
- Parent:
- 5:7a63cb7ec666
- Child:
- 7:278339a9eeba
File content as of revision 6:9aeb18bebe85:
#include "mbed.h" #include "glibr.h" Serial USB_link(USBTX, USBRX); // USB initialization //PwmOut LED(A2); // LED initialization glibr capt1(D4,D5); // I²C initialization : D4 = SDA ; D5 = SCL CAN can1(PA_11, PA_12); // CAN initialization CANMessage msg; bool initialization(void) { // USB initialization USB_link.baud(115200); USB_link.printf("Debut prog\r\n"); // CAN init can1.frequency(1000000); // LED initialization // LED.period_ms(10); // LED.write(0.5); // sensor initalization if( (capt1.ginit()) && (capt1.enableLightSensor(true)) && (capt1.enableProximitySensor(true)) ) { return true; } else { return false; } } int main (void) { uint16_t r,g,b; uint8_t a ; char color; 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); if (a<200) { color = 0 ; // 0 means no object being measured } else if (r > g ) { color = 1 ; // 1 means red } else { color = 2 ; // 2 means green } //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 } } } }