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: LSM9DS0 PinDetect mbed
main.cpp
00001 #include "mbed.h" 00002 #include "LSM9DS0.h" 00003 #include "PinDetect.h" 00004 00005 // SDO_XM and SDO_G are pulled up, so our addresses are: 00006 #define LSM9DS0_XM_ADDR 0x1D // Would be 0x1E if SDO_XM is LOW 00007 #define LSM9DS0_G_ADDR 0x6B // Would be 0x6A if SDO_G is LOW 00008 00009 LSM9DS0 imu(p9, p10, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR); // IMU 00010 DigitalIn L(p21); // Left flipper 00011 DigitalIn R(p22); // Right flipper 00012 Serial pc(USBTX, USBRX); // Serial read out 00013 AnalogIn plunger(p20); // Slide potentiometer 00014 DigitalOut led1(LED1); //left 00015 DigitalOut led2(LED2); //right 00016 DigitalOut led3(LED3); //coin 00017 AnalogIn coin(p19); // IR Sensor 00018 00019 //variables changed by callback functions to be printed to serial 00020 int coins=0; 00021 int volatile left=0; 00022 int volatile right=0; 00023 int plungers=0; 00024 void L_hit_callback (void) 00025 { 00026 left=1; 00027 } 00028 00029 void R_hit_callback (void) 00030 { 00031 right=1; 00032 } 00033 00034 int main() 00035 { 00036 // Use the begin() function to initialize the LSM9DS0 library. 00037 // You can either call it with no parameters (the easy way): 00038 uint16_t status = imu.begin(); 00039 00040 //Make sure communication is working (DEBUG) 00041 pc.printf("LSM9DS0 WHO_AM_I's returned: 0x%X\n", status); 00042 pc.printf("Should be 0x49D4\n\n"); 00043 while(1) { 00044 //Setup default values 00045 plungers=0; 00046 led1=L; 00047 led2=R; 00048 left=L; 00049 right=R; 00050 00051 // imu readings 00052 imu.readAccel(); 00053 float heading = imu.calcHeading(); 00054 00055 //detect if coin was inserted 00056 if (coin>0.35f) { 00057 led3=1; 00058 coins=1; 00059 } else { 00060 led3=0; 00061 coins=0; 00062 } 00063 // which speed to launch ball at 00064 if (plunger<0.25f) { 00065 plungers=1; 00066 } else if(plunger<0.5f) { 00067 plungers=2; 00068 } else if(plunger<0.75f) { 00069 plungers=3; 00070 } else if(plunger<2.0f) { 00071 plungers=4; 00072 } 00073 // Write to serial - order matters (left, right coin, plunger, imu) 00074 pc.printf("%i,%i,%i,%i,%.1f\r\n",left,right,coins,plungers, imu.ay); 00075 wait(0.20); 00076 } 00077 }
Generated on Sat Jul 16 2022 13:18:40 by
1.7.2