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: VL6180x X_NUCLEO_COMMON X_NUCLEO_IHM01A1 mbed
Fork of 1-DoorCloser by
main.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file main.cpp 00004 * @author Julien Tiron, FIP Télécom Bretagne 00005 * @version V1.0.0 00006 * @date March 23th, 2016 00007 * @brief DoorCloser robot main code 00008 ****************************************************************************** 00009 **/ 00010 00011 /* Includes ------------------------------------------------------------------*/ 00012 00013 #include "mbed.h" 00014 #include "DevSPI.h" 00015 #include "l6474_class.h" 00016 #include "DevI2C.h" 00017 #include "vl6180x_class.h" 00018 #include "VL6180x.h" 00019 00020 /* Definitions ---------------------------------------------------------------*/ 00021 00022 #define VL6180X_ADDRESS 0x29 00023 00024 /* Variables -----------------------------------------------------------------*/ 00025 00026 /* Start and Stop Component */ 00027 InterruptIn startup(PC_1); 00028 Ticker game_length; 00029 volatile bool start = 1; 00030 volatile bool end = 1; 00031 char data = 0x08 | (char)64; 00032 bool tag = true; 00033 int i2cAddres=0x70; // Address of DS1307 is 0x68 (7 bit address) 00034 int i2c8BitAddres= i2cAddres <<1; // Convert to 8bit addressing used by mbed 00035 00036 /* Motor Control Component */ 00037 L6474 *motor1; 00038 L6474 *motor2; 00039 00040 /* Distance Sensors Component */ 00041 /*DevI2C *i2c =new DevI2C(D14, D15); 00042 VL6180X sensor1(i2c); 00043 VL6180X sensor2(i2c); 00044 VL6180X sensor3(i2c);*/ 00045 I2C i2c(D14, D15); 00046 VL6180x sensor(D14, D15, VL6180X_ADDRESS<<1); 00047 00048 /* Functions -----------------------------------------------------------------*/ 00049 00050 void go() 00051 { 00052 start = 0; 00053 } 00054 00055 void stop() 00056 { 00057 end = 0; 00058 } 00059 00060 void init_sensor() 00061 { 00062 00063 } 00064 00065 void switch_sensor(int number) 00066 { 00067 00068 } 00069 00070 /* Main ----------------------------------------------------------------------*/ 00071 00072 int main() 00073 { 00074 /*----- Initialization. -----*/ 00075 00076 /* Initializing SPI bus. */ 00077 DevSPI dev_spi(D11, D12, D13); 00078 00079 /* Initializing Motor Control Components. */ 00080 motor1 = new L6474(D2, D8, D7, D9, D10, dev_spi); 00081 motor2 = new L6474(D2, D8, D4, D3, D10, dev_spi); 00082 if (motor1->Init() != COMPONENT_OK) 00083 exit(EXIT_FAILURE); 00084 if (motor2->Init() != COMPONENT_OK) 00085 exit(EXIT_FAILURE); 00086 int result = i2c.write(i2c8BitAddres, &data, 1 ); 00087 sensor.VL6180xDefautSettings(); 00088 00089 /* Interrupt to start the robot */ 00090 startup.fall(&go); 00091 00092 while(start) { 00093 /* Waiting code */ 00094 } 00095 00096 while(end) { 00097 /* In-game code */ 00098 00099 /* Interrupt to stop the robot */ 00100 game_length.attach(&stop, 10); //1 minutes 30 secondes pour la Coupe 00101 00102 if(sensor.getDistance()<100) { 00103 printf("1"); 00104 if(tag == false) { 00105 motor1->Run(StepperMotor::FWD); 00106 motor2->Run(StepperMotor::FWD); 00107 00108 tag = true; 00109 } 00110 } else { 00111 printf("0"); 00112 if(tag == true) { 00113 motor1->Run(StepperMotor::FWD); 00114 motor2->Run(StepperMotor::BWD); 00115 00116 tag = false; 00117 } 00118 } 00119 wait_ms(100); 00120 /* Waiting until delay has expired. */ 00121 } 00122 00123 motor1->HardStop(); 00124 motor2->HardStop(); 00125 00126 motor1->WaitWhileActive(); 00127 motor2->WaitWhileActive(); 00128 }
Generated on Tue Jul 26 2022 05:07:42 by
1.7.2
