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.
Diff: main.cpp
- Revision:
- 2:c7897a3f5f11
- Parent:
- 1:b36bbc1c6d27
diff -r b36bbc1c6d27 -r c7897a3f5f11 main.cpp
--- a/main.cpp Sat Apr 11 08:15:48 2020 +0000
+++ b/main.cpp Wed Apr 22 11:50:00 2020 +0000
@@ -7,55 +7,84 @@
DigitalOut led1(LED1);
InterruptIn sw(USER_BUTTON);
+
+// Sensor Interrupts
+InterruptIn button1(D2);
+InterruptIn button2(D3);
+InterruptIn button3(D4);
+InterruptIn button4(D5);
+InterruptIn ir1(D6);
+
+
Thread eventthread;
Thread imuthread;
bool read_imu_isrunning;
-
// Pin defines
DigitalOut led_green(D4);
-//-----------------------------------------------------
-//IMU
-//-----------------------------------------------------
+Serial* pc;
+MPU9250* mpu9250;
+
-void rise_handler(void)
+void button1Event()
+{
+ pc->printf("Button 1\n\r");
+}
+
+void button2Event()
+{
+ pc->printf("Button 2\n\r");
+}
+
+void button3Event()
{
- printf("rise_handler in context %p\r\n", Thread::gettid());
- // Toggle LED
- led1 = !led1;
- for (int i = 0; i<10; i++) {
- led_green = !led_green;
- wait(0.5);
+ pc->printf("Button 3\n\r");
+}
+
+void button4Event()
+{
+ pc->printf("Button 4\n\r");
+}
+
+void ir1Event()
+{
+ pc->printf("IR-1\n\r");
+ mpu9250->vx_old = 10.5;
+}
+
+void readIMUThread()
+{
+ pc->printf("in IMU-Thread\n\r");
+ while(1) {
+ pc->printf("vx: %f\n\r", mpu9250->getVBuffer());
+ wait(0.4);
}
}
-void fall_handler(void)
-{
- printf("fall_handler in context %p\r\n", Thread::gettid());
- // Toggle LED
- led1 = !led1;
-}
-
-
-
-
int main()
{
- //pc.baud(9600);
- //imuSetup();
- //imuthread.start(readIMU);
+ pc = new Serial(USBTX, USBRX);
+ pc->baud(9600);
+
+ // Setup of IMU (Constructor calls setup-function)
+ mpu9250 = new MPU9250(pc);
+
+ imuthread.start(readIMUThread);
// Request the shared queue
EventQueue *queue = mbed_event_queue();
- //printf("Starting in context %p\r\n", Thread::gettid());
+ pc->printf("Starting in context %p\r\n", Thread::gettid());
+
- // The 'rise' handler will execute in IRQ context
- sw.rise(queue->event(rise_handler));
- // The 'fall' handler will execute in the context of the shared queue (actually the main thread)
- sw.fall(queue->event(fall_handler));
+ button1.rise(queue->event(button1Event));
+ button2.rise(queue->event(button2Event));
+ button3.rise(queue->event(button3Event));
+ button4.rise(queue->event(button4Event));
+ ir1.rise(queue->event(ir1Event));
+
// Setup complete, so we now dispatch the shared queue from main
- queue->dispatch_forever();
+ queue->dispatch();
}
\ No newline at end of file