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: MPU9250_SPI SDFileSystem XBeeLib
main.cpp@8:ba93a973f967, 2017-10-12 (annotated)
- Committer:
- gusteibolt
- Date:
- Thu Oct 12 19:00:33 2017 +0000
- Revision:
- 8:ba93a973f967
- Parent:
- 7:ebaaff27840b
- Child:
- 10:577e1fc4453e
Half-fixed events
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gusteibolt | 1:a6dc717fb060 | 1 | /* |
| gusteibolt | 1:a6dc717fb060 | 2 | * Los Putacos |
| gusteibolt | 1:a6dc717fb060 | 3 | * Copyright (C) 2017, All rights reserved. |
| gusteibolt | 1:a6dc717fb060 | 4 | * ________________________________________ |
| gusteibolt | 1:a6dc717fb060 | 5 | * |
| gusteibolt | 1:a6dc717fb060 | 6 | * Created by: Gustavo Campana, Michael Schmidt, Miguel Lopez |
| gusteibolt | 1:a6dc717fb060 | 7 | * Date: 11-Oct-2017 |
| gusteibolt | 1:a6dc717fb060 | 8 | * Version: V0.1 |
| gusteibolt | 1:a6dc717fb060 | 9 | */ |
| gusteibolt | 1:a6dc717fb060 | 10 | |
| gusteibolt | 1:a6dc717fb060 | 11 | //----------------------------------------------------------------- |
| gusteibolt | 1:a6dc717fb060 | 12 | // Board: NUCLEO - F401RE |
| gusteibolt | 1:a6dc717fb060 | 13 | // Version: MR1136 rev C |
| gusteibolt | 1:a6dc717fb060 | 14 | //----------------------------------------------------------------- |
| gusteibolt | 1:a6dc717fb060 | 15 | |
| gusteibolt | 1:a6dc717fb060 | 16 | //----------------------------------------------------------------- |
| gusteibolt | 1:a6dc717fb060 | 17 | // Includes |
| gusteibolt | 0:73cd0cb02330 | 18 | #include "mbed.h" |
| gusteibolt | 0:73cd0cb02330 | 19 | #include "rtos.h" |
| gusteibolt | 3:26aeff25f610 | 20 | #include "mbed_events.h" |
| gusteibolt | 3:26aeff25f610 | 21 | |
| gusteibolt | 3:26aeff25f610 | 22 | #include "configuration.h" |
| gusteibolt | 8:ba93a973f967 | 23 | //#include "event.h" |
| gusteibolt | 7:ebaaff27840b | 24 | #include "pin.h" |
| gusteibolt | 3:26aeff25f610 | 25 | #include "MPU9250.h" |
| gusteibolt | 1:a6dc717fb060 | 26 | //----------------------------------------------------------------- |
| gusteibolt | 0:73cd0cb02330 | 27 | |
| gusteibolt | 1:a6dc717fb060 | 28 | //----------------------------------------------------------------- |
| gusteibolt | 1:a6dc717fb060 | 29 | // Declarations |
| gusteibolt | 3:26aeff25f610 | 30 | Timer t; //Timer µS time-stamp |
| gusteibolt | 3:26aeff25f610 | 31 | |
| gusteibolt | 3:26aeff25f610 | 32 | EventQueue queue(32 * EVENTS_EVENT_SIZE); //Event |
| gusteibolt | 3:26aeff25f610 | 33 | |
| gusteibolt | 3:26aeff25f610 | 34 | Serial pc(USBTX, USBRX); // PC Serial (Debug) |
| gusteibolt | 3:26aeff25f610 | 35 | |
| gusteibolt | 3:26aeff25f610 | 36 | MPU9250 mpu9250; // IMU MPU-9255 by Kris Winer |
| gusteibolt | 1:a6dc717fb060 | 37 | //----------------------------------------------------------------- |
| gusteibolt | 1:a6dc717fb060 | 38 | |
| gusteibolt | 1:a6dc717fb060 | 39 | //----------------------------------------------------------------- |
| gusteibolt | 1:a6dc717fb060 | 40 | // Global Variables |
| gusteibolt | 3:26aeff25f610 | 41 | // Your code here! |
| gusteibolt | 1:a6dc717fb060 | 42 | //----------------------------------------------------------------- |
| gusteibolt | 1:a6dc717fb060 | 43 | |
| gusteibolt | 1:a6dc717fb060 | 44 | //----------------------------------------------------------------- |
| gusteibolt | 8:ba93a973f967 | 45 | void print_event(void const *argv, int i) { |
| gusteibolt | 8:ba93a973f967 | 46 | pc.printf("%d",i); |
| gusteibolt | 8:ba93a973f967 | 47 | pc.printf((const char*)argv); |
| gusteibolt | 8:ba93a973f967 | 48 | } |
| gusteibolt | 8:ba93a973f967 | 49 | //----------------------------------------------------------------- |
| gusteibolt | 8:ba93a973f967 | 50 | |
| gusteibolt | 8:ba93a973f967 | 51 | //----------------------------------------------------------------- |
| gusteibolt | 8:ba93a973f967 | 52 | void blink_event(DigitalOut pin){ |
| gusteibolt | 8:ba93a973f967 | 53 | if(pin.read()==0){ |
| gusteibolt | 8:ba93a973f967 | 54 | pin = 1; |
| gusteibolt | 8:ba93a973f967 | 55 | } |
| gusteibolt | 8:ba93a973f967 | 56 | else{ |
| gusteibolt | 8:ba93a973f967 | 57 | pin = 0; |
| gusteibolt | 8:ba93a973f967 | 58 | } |
| gusteibolt | 8:ba93a973f967 | 59 | } |
| gusteibolt | 8:ba93a973f967 | 60 | //----------------------------------------------------------------- |
| gusteibolt | 8:ba93a973f967 | 61 | |
| gusteibolt | 8:ba93a973f967 | 62 | //----------------------------------------------------------------- |
| gusteibolt | 8:ba93a973f967 | 63 | void println_event(){ |
| gusteibolt | 8:ba93a973f967 | 64 | pc.printf("Arroz, feijao e batata\r\n"); |
| gusteibolt | 8:ba93a973f967 | 65 | } |
| gusteibolt | 8:ba93a973f967 | 66 | //----------------------------------------------------------------- |
| gusteibolt | 8:ba93a973f967 | 67 | |
| gusteibolt | 8:ba93a973f967 | 68 | //----------------------------------------------------------------- |
| gusteibolt | 7:ebaaff27840b | 69 | void setup(){ |
| gusteibolt | 3:26aeff25f610 | 70 | |
| gusteibolt | 3:26aeff25f610 | 71 | // PC Serial (Debug) baudrate |
| gusteibolt | 3:26aeff25f610 | 72 | pc.baud(9600); |
| gusteibolt | 3:26aeff25f610 | 73 | pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
| gusteibolt | 3:26aeff25f610 | 74 | |
| gusteibolt | 3:26aeff25f610 | 75 | // Task queue |
| gusteibolt | 3:26aeff25f610 | 76 | int task1_id = queue.call_every(1000, printf, "called every 1 seconds\n"); |
| gusteibolt | 3:26aeff25f610 | 77 | int task2_id = queue.call_every(2500, printf, "called every 2.5 seconds\n"); |
| gusteibolt | 8:ba93a973f967 | 78 | int task3_id = queue.call_every(3000, print_event, (void *)"called every 3 seconds\n", t.read()); |
| gusteibolt | 8:ba93a973f967 | 79 | int task4_id = queue.call_every(50, blink_event, led1); |
| gusteibolt | 8:ba93a973f967 | 80 | int task5_id = queue.call_every(500, println_event); |
| gusteibolt | 0:73cd0cb02330 | 81 | } |
| gusteibolt | 1:a6dc717fb060 | 82 | //----------------------------------------------------------------- |
| gusteibolt | 0:73cd0cb02330 | 83 | |
| gusteibolt | 1:a6dc717fb060 | 84 | //----------------------------------------------------------------- |
| Mister_Lopez | 4:56e903769e94 | 85 | void initMPU9250() |
| Mister_Lopez | 4:56e903769e94 | 86 | { |
| Mister_Lopez | 4:56e903769e94 | 87 | // Initialize MPU9250 device |
| Mister_Lopez | 4:56e903769e94 | 88 | // wake up device |
| gusteibolt | 5:18e89e309715 | 89 | //writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x00); // Clear sleep mode bit (6), enable all sensors |
| Mister_Lopez | 4:56e903769e94 | 90 | } |
| Mister_Lopez | 4:56e903769e94 | 91 | |
| Mister_Lopez | 4:56e903769e94 | 92 | //----------------------------------------------------------------- |
| Mister_Lopez | 4:56e903769e94 | 93 | |
| Mister_Lopez | 4:56e903769e94 | 94 | //----------------------------------------------------------------- |
| gusteibolt | 0:73cd0cb02330 | 95 | int main() |
| gusteibolt | 0:73cd0cb02330 | 96 | { |
| gusteibolt | 7:ebaaff27840b | 97 | setup(); // Initial setups |
| gusteibolt | 3:26aeff25f610 | 98 | |
| Mister_Lopez | 4:56e903769e94 | 99 | |
| Mister_Lopez | 4:56e903769e94 | 100 | //Reading the analog input (Microphone) array = micro.read_u16(); |
| Mister_Lopez | 4:56e903769e94 | 101 | |
| gusteibolt | 8:ba93a973f967 | 102 | t.start(); // Start timer |
| Mister_Lopez | 4:56e903769e94 | 103 | |
| gusteibolt | 0:73cd0cb02330 | 104 | while (true) { |
| gusteibolt | 3:26aeff25f610 | 105 | queue.dispatch(); |
| gusteibolt | 0:73cd0cb02330 | 106 | } |
| gusteibolt | 0:73cd0cb02330 | 107 | } |
| gusteibolt | 1:a6dc717fb060 | 108 | //----------------------------------------------------------------- |

