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-06
- Revision:
- 5:7a63cb7ec666
- Parent:
- 3:f41f244de0b3
- Child:
- 6:9aeb18bebe85
File content as of revision 5:7a63cb7ec666:
#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(D0, D1); // CAN initialization bool initialization(void) { // USB initialization USB_link.baud(115200); USB_link.format(8, SerialBase::None, 1); // 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) { 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); if (a<100) { color = 0 ; // 0 means no object being measured } else if (r > g ) { color = 1 ; // 1 means red } else if (g > r ) { color = 2 ; // 2 means green } //can1.write(CANMessage(1200,&color,1)); // USB_link.printf("color : %c", color); } return 0; }