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: mbed MPU6050 Pozicija
main.cpp@1:19dc1ee367a9, 2020-05-04 (annotated)
- Committer:
- dmausa
- Date:
- Mon May 04 12:03:50 2020 +0000
- Revision:
- 1:19dc1ee367a9
- Parent:
- 0:eeb65c4f3a00
Tvz,specelo,Mikroupravljaci
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmausa | 0:eeb65c4f3a00 | 1 | #include "mbed.h" |
dmausa | 0:eeb65c4f3a00 | 2 | #include "MPU6050.h" |
dmausa | 0:eeb65c4f3a00 | 3 | #include "Pozicija.h" |
dmausa | 0:eeb65c4f3a00 | 4 | |
dmausa | 0:eeb65c4f3a00 | 5 | Serial pc(USBTX, USBRX); |
dmausa | 0:eeb65c4f3a00 | 6 | MPU6050 mpu(0x68); |
dmausa | 0:eeb65c4f3a00 | 7 | Pozicije poz(mpu); |
dmausa | 0:eeb65c4f3a00 | 8 | |
dmausa | 0:eeb65c4f3a00 | 9 | |
dmausa | 0:eeb65c4f3a00 | 10 | DigitalOut myled1(LED1); //Objekti digitalnih izlaza (spojeni na ugradjene LED diode) |
dmausa | 0:eeb65c4f3a00 | 11 | DigitalOut myled4(LED4); //Objekti digitalnih izlaza (spojeni na ugradjene LED diode) |
dmausa | 0:eeb65c4f3a00 | 12 | |
dmausa | 0:eeb65c4f3a00 | 13 | InterruptIn button(p21); //Interrupt na pin 21 |
dmausa | 0:eeb65c4f3a00 | 14 | |
dmausa | 0:eeb65c4f3a00 | 15 | Timer debounce; |
dmausa | 0:eeb65c4f3a00 | 16 | Ticker TickTack; |
dmausa | 0:eeb65c4f3a00 | 17 | |
dmausa | 0:eeb65c4f3a00 | 18 | |
dmausa | 0:eeb65c4f3a00 | 19 | void PrintOut() |
dmausa | 0:eeb65c4f3a00 | 20 | { |
dmausa | 0:eeb65c4f3a00 | 21 | myled1=myled4; |
dmausa | 0:eeb65c4f3a00 | 22 | myled4=!myled4; //Blinkanje ledicama |
dmausa | 0:eeb65c4f3a00 | 23 | |
dmausa | 0:eeb65c4f3a00 | 24 | pc.printf("Trenutne koordinate osi: \n"); |
dmausa | 0:eeb65c4f3a00 | 25 | pc.printf("Acc X : %d \r", poz.getAccX() ); |
dmausa | 0:eeb65c4f3a00 | 26 | pc.printf("Acc Y : %d \r", poz.getAccY() ); |
dmausa | 0:eeb65c4f3a00 | 27 | pc.printf("Acc Z : %d \r", poz.getAccZ() ); |
dmausa | 0:eeb65c4f3a00 | 28 | |
dmausa | 0:eeb65c4f3a00 | 29 | pc.printf("Rotacija X : %d \r", poz.getGyX() ); |
dmausa | 0:eeb65c4f3a00 | 30 | pc.printf("Rotacija Y : %d \r", poz.getGyY() ); |
dmausa | 0:eeb65c4f3a00 | 31 | pc.printf("Rotacija Z : %d \r", poz.getGyZ() ); |
dmausa | 0:eeb65c4f3a00 | 32 | } |
dmausa | 0:eeb65c4f3a00 | 33 | |
dmausa | 0:eeb65c4f3a00 | 34 | void Update() |
dmausa | 0:eeb65c4f3a00 | 35 | { |
dmausa | 0:eeb65c4f3a00 | 36 | if (debounce.read_ms()>200) { //200 ms od zadnjeg interrupta |
dmausa | 0:eeb65c4f3a00 | 37 | |
dmausa | 0:eeb65c4f3a00 | 38 | if(mpu.testConnection()) { //Testira konekciju s MPU6050 |
dmausa | 0:eeb65c4f3a00 | 39 | |
dmausa | 0:eeb65c4f3a00 | 40 | pc.printf("Konekcija OK\n"); |
dmausa | 0:eeb65c4f3a00 | 41 | poz.Update(); |
dmausa | 0:eeb65c4f3a00 | 42 | } else { |
dmausa | 0:eeb65c4f3a00 | 43 | pc.printf("Konekcija !OK\n"); |
dmausa | 0:eeb65c4f3a00 | 44 | } |
dmausa | 0:eeb65c4f3a00 | 45 | } |
dmausa | 0:eeb65c4f3a00 | 46 | |
dmausa | 0:eeb65c4f3a00 | 47 | debounce.reset(); //Reser debounce timera na 0 ms |
dmausa | 0:eeb65c4f3a00 | 48 | } |
dmausa | 0:eeb65c4f3a00 | 49 | |
dmausa | 0:eeb65c4f3a00 | 50 | void setup() |
dmausa | 0:eeb65c4f3a00 | 51 | { |
dmausa | 0:eeb65c4f3a00 | 52 | mpu.initialize(); //"Budi" mpu i postavlja osnovne parametre |
dmausa | 0:eeb65c4f3a00 | 53 | |
dmausa | 0:eeb65c4f3a00 | 54 | if(mpu.testConnection()) { // Testira konekciju |
dmausa | 0:eeb65c4f3a00 | 55 | pc.printf("MPU uspjesno spojen \n"); |
dmausa | 0:eeb65c4f3a00 | 56 | } else { |
dmausa | 0:eeb65c4f3a00 | 57 | pc.printf("MPU nije pronaden \n"); |
dmausa | 0:eeb65c4f3a00 | 58 | } |
dmausa | 0:eeb65c4f3a00 | 59 | |
dmausa | 0:eeb65c4f3a00 | 60 | debounce.start(); //Pokreče debounce Timer |
dmausa | 0:eeb65c4f3a00 | 61 | button.rise(Update); //Na rastuci brid pokreče funkciju "Update" |
dmausa | 0:eeb65c4f3a00 | 62 | |
dmausa | 0:eeb65c4f3a00 | 63 | TickTack.attach(&PrintOut,2) ;//Svake 2 sekunde pokrece funkciju za ispis pozicija |
dmausa | 0:eeb65c4f3a00 | 64 | } |
dmausa | 0:eeb65c4f3a00 | 65 | |
dmausa | 0:eeb65c4f3a00 | 66 | |
dmausa | 0:eeb65c4f3a00 | 67 | int main() |
dmausa | 0:eeb65c4f3a00 | 68 | { |
dmausa | 0:eeb65c4f3a00 | 69 | setup(); |
dmausa | 0:eeb65c4f3a00 | 70 | } |