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
00001 #include "mbed.h" 00002 #include "mbed_events.h" 00003 #include "MPU9250.h" 00004 00005 #define SAMPLE_TIME 100 00006 00007 DigitalOut led1(LED1); 00008 InterruptIn sw(USER_BUTTON); 00009 00010 00011 // Sensor Interrupts 00012 InterruptIn button1(D2); 00013 InterruptIn button2(D3); 00014 InterruptIn button3(D4); 00015 InterruptIn button4(D5); 00016 InterruptIn ir1(D6); 00017 00018 00019 Thread eventthread; 00020 Thread imuthread; 00021 bool read_imu_isrunning; 00022 00023 // Pin defines 00024 DigitalOut led_green(D4); 00025 00026 Serial* pc; 00027 MPU9250* mpu9250; 00028 00029 00030 void button1Event() 00031 { 00032 pc->printf("Button 1\n\r"); 00033 } 00034 00035 void button2Event() 00036 { 00037 pc->printf("Button 2\n\r"); 00038 } 00039 00040 void button3Event() 00041 { 00042 pc->printf("Button 3\n\r"); 00043 } 00044 00045 void button4Event() 00046 { 00047 pc->printf("Button 4\n\r"); 00048 } 00049 00050 void ir1Event() 00051 { 00052 pc->printf("IR-1\n\r"); 00053 mpu9250->vx_old = 10.5; 00054 } 00055 00056 void readIMUThread() 00057 { 00058 pc->printf("in IMU-Thread\n\r"); 00059 while(1) { 00060 pc->printf("vx: %f\n\r", mpu9250->getVBuffer()); 00061 wait(0.4); 00062 } 00063 } 00064 00065 00066 00067 int main() 00068 { 00069 pc = new Serial(USBTX, USBRX); 00070 pc->baud(9600); 00071 00072 // Setup of IMU (Constructor calls setup-function) 00073 mpu9250 = new MPU9250(pc); 00074 00075 imuthread.start(readIMUThread); 00076 00077 // Request the shared queue 00078 EventQueue *queue = mbed_event_queue(); 00079 pc->printf("Starting in context %p\r\n", Thread::gettid()); 00080 00081 00082 button1.rise(queue->event(button1Event)); 00083 button2.rise(queue->event(button2Event)); 00084 button3.rise(queue->event(button3Event)); 00085 button4.rise(queue->event(button4Event)); 00086 ir1.rise(queue->event(ir1Event)); 00087 00088 // Setup complete, so we now dispatch the shared queue from main 00089 queue->dispatch(); 00090 }
Generated on Thu Jul 14 2022 14:36:18 by
