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.
Dependencies: TCS3200 X_NUCLEO_53L0A1 mbed
main.cpp
00001 #include "mbed.h" 00002 #include "XNucleo53L0A1.h" 00003 #include "TCS3200.h" 00004 #include <stdio.h> 00005 00006 #define VL53L0_I2C_SDA D4 00007 #define VL53L0_I2C_SCL D5 00008 00009 #define NOT_RECEIVE 0 00010 #define RED_RECEIVE 1 00011 #define BLUE_RECEIVE 2 00012 #define YELLOW_RECIEVE 3 00013 00014 00015 TCS3200 color(PB_5, PB_2, PC_4);//カラーセンサ 00016 static XNucleo53L0A1 *board=NULL; 00017 int count = 0; 00018 int red_count = 0; 00019 int blue_count = 0; 00020 int mode = NOT_RECEIVE; 00021 00022 int main(){ 00023 long red, green, blue, clear; 00024 int status; 00025 uint32_t distance; 00026 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL); 00027 board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2); 00028 status = board->init_board(); 00029 if (status) { 00030 printf("Failed to init board!\r\n"); 00031 return 0; 00032 } 00033 while (1) { 00034 status = board->sensor_centre->get_distance(&distance); 00035 red = color.ReadRed(); 00036 blue = color.ReadBlue(); 00037 clear = color.ReadClear(); 00038 if(clear <= 30 && distance <= 1000){ 00039 count++; 00040 } 00041 if(count >= 1000){ 00042 if(red <= 40 && green >= 80 && blue >= 70){ 00043 red_count++; 00044 }else if(red >= 80 && green >= 60 && blue <= 40){ 00045 blue_count++; 00046 } 00047 count = 0; 00048 } 00049 if(red_count >= 1000 && distance >= 2000){ 00050 mode = RED_RECEIVE; 00051 red_count = 0; 00052 }else if(blue_count >= 1000 && distance >= 2000){ 00053 mode = BLUE_RECEIVE; 00054 blue_count = 0; 00055 } 00056 } 00057 }
Generated on Wed Jul 13 2022 11:00:06 by
1.7.2