moruxa が 2021年02月27日19時50分49秒 に編集
コメント無し
本文の変更
# 製作意図 我々の業界である高速道路での現場作業には車両突入の危険が付きまといます。 この装置は現場の作業員を車両突入から保護する目的で実装したプロトタイプです。 距離センサーを用いて車両突入を未然に検知し、作業員に知らせます。 # 材料 - NUCLEO-F401RE Mbed対応マイコンです。 - P-NUCLEO-53L0A1 距離センサーの評価ボードです。(本当はLIDAR-Lite v3が使いたいのですが) - 抵抗入り黄色LED 秋月で売ってる抵抗入りLEDです。(本当は大音量ブザーが使いたいのですが) # コード 概要:距離センサーで物体を検知したら、7セグLEDにSEnSと表示する(黄色LEDを光らせる) ```c:main.c /* * This VL53L0X Expansion board test application performs range measurements * using the onboard embedded centre sensor, in singleshot, polling mode. * Measured ranges are displayed on the on-board 4-digit display. * * The User Blue button stops the current measurement and entire program, * releasing all resources. * * The Reset button can be used to restart the program. */ #include <string.h> #include <stdio.h> #include "mbed.h" #include "XNucleo53L0A1.h" #include "VL53L0X.h" #define VL53L0_I2C_SDA D14 #define VL53L0_I2C_SCL D15 static XNucleo53L0A1 *board = NULL; VL53L0X_RangingMeasurementData_t data_sensor_centre; OperatingMode operating_mode; /* flags that handle interrupt request */ bool int_stop_measure = false; int a = 0; /* ISR callback function of the user blue button to stop program */ void stop_measure_irq(void) { int_stop_measure = true; a=1; printf("interrupted.\n\r"); } DigitalOut led(PA_5); /* On board 4 digit local display refresh */ void display_refresh(VL53L0X_RangingMeasurementData_t sensor_range_data) { char str[5]; int i; if (sensor_range_data.RangeStatus == 0) { // we have a valid range. sprintf(str, "%4d", i=sensor_range_data.RangeMilliMeter); if (i<2000) { led=1; board->display->display_string("SENS"); wait(3); } else { led=0; } } else { sprintf(str, "%s", "----"); led=0; } board->display->display_string(str); } /*=================================== Main ================================== Press the blue user button to stop measurements in progress =============================================================================*/ int main() { DigitalIn btn(PC_13); DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL); int status; /* creates the 53L0A1 expansion board singleton obj */ board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2); board->display->display_string("53L0"); /* init the 53L0A1 expansion board with default values */ status = board->init_board(); if (status) printf("Failed to init board!\n\r"); operating_mode = range_single_shot_polling; /* start the measure on sensor centre */ status = board->sensor_centre->start_measurement(operating_mode, NULL); #if USER_BUTTON == PC_13 // we are cross compiling for Nucleo-f401 printf("PC_13 enabled.\n\r"); InterruptIn stop_button(USER_BUTTON); stop_button.mode(PullDown); stop_button.rise(&stop_measure_irq); #endif if (!status) { while (1) { // infinite loop. can be broken by pressing Blue (User) button. wait(0.1); status = board->sensor_centre->get_measurement(operating_mode, &data_sensor_centre); display_refresh(data_sensor_centre); printf("%d,%d\n\r", a, btn ? 1 :0); if (int_stop_measure == true) { // Blue Button isr was triggered status = board->sensor_centre->stop_measurement(operating_mode); // stop the measure and exit //int_stop_measure = false; printf("\nProgram stopped!\n\n\r"); break; } } } board->display->display_string("BYE"); delete board; } ``` # 完成写真
![キャプションを入力できます](https://camo.elchika.com/fd2d711c4f5b43449668af4cce1e62cef1bbd4fb/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f39353433373162332d363031622d343039622d396462642d3761363934393061306562642f34386332373132362d623132622d346338642d396536302d653830316265656132626237/)