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: JoystickLinija IRremote mbed Tipkalo UniServ_linijapogona umotor_linijapogona
main.cpp@1:055ae04a8003, 2017-02-08 (annotated)
- Committer:
- mario_meh
- Date:
- Wed Feb 08 08:41:14 2017 +0000
- Revision:
- 1:055ae04a8003
- Parent:
- 0:4cac97044e74
Debounce tipkalo
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mario_meh | 1:055ae04a8003 | 1 | /** Projektiranje ugradbenih računalnih sustava |
| mario_meh | 1:055ae04a8003 | 2 | * Interakcija sa linijom |
| mario_meh | 1:055ae04a8003 | 3 | * @author: mario_meh |
| mario_meh | 1:055ae04a8003 | 4 | * |
| mario_meh | 1:055ae04a8003 | 5 | */ |
| mario_meh | 0:4cac97044e74 | 6 | #include "mbed.h" |
| mario_meh | 1:055ae04a8003 | 7 | #include "tipkalo.h" |
| mario_meh | 1:055ae04a8003 | 8 | #include "joystick.h" |
| mario_meh | 0:4cac97044e74 | 9 | #include "IRremote.h" |
| mario_meh | 1:055ae04a8003 | 10 | #include "UniServ.h" |
| mario_meh | 1:055ae04a8003 | 11 | #include "umotor.h" |
| mario_meh | 0:4cac97044e74 | 12 | |
| mario_meh | 1:055ae04a8003 | 13 | DigitalOut kontrola(PTE29); |
| mario_meh | 0:4cac97044e74 | 14 | Serial serial(USBTX, USBRX); // PC |
| mario_meh | 1:055ae04a8003 | 15 | DigitalOut led(PTB19); |
| mario_meh | 1:055ae04a8003 | 16 | IRrecv pinIn(PTB3); // IR |
| mario_meh | 0:4cac97044e74 | 17 | I2C i2c(PTC9, PTC8); // SDA, SCL |
| mario_meh | 0:4cac97044e74 | 18 | //Tipkalo led(PT); // LED svjetlo |
| mario_meh | 1:055ae04a8003 | 19 | UniServ sMotor(PTB2); |
| mario_meh | 1:055ae04a8003 | 20 | Timer t; |
| mario_meh | 1:055ae04a8003 | 21 | Serial pc(USBTX, USBRX); // tx, rx |
| mario_meh | 1:055ae04a8003 | 22 | |
| mario_meh | 0:4cac97044e74 | 23 | |
| mario_meh | 0:4cac97044e74 | 24 | const int addr = 0x0A; |
| mario_meh | 1:055ae04a8003 | 25 | char remote[4]; |
| mario_meh | 0:4cac97044e74 | 26 | |
| mario_meh | 0:4cac97044e74 | 27 | int main() { |
| mario_meh | 1:055ae04a8003 | 28 | |
| mario_meh | 0:4cac97044e74 | 29 | //--------------------------------------------------tipke pogona |
| mario_meh | 1:055ae04a8003 | 30 | Tipkalo *bTipka = new Tipkalo(); |
| mario_meh | 1:055ae04a8003 | 31 | if(bTipka->LStatus() == true) { |
| mario_meh | 1:055ae04a8003 | 32 | kontrola = 1; |
| mario_meh | 1:055ae04a8003 | 33 | } |
| mario_meh | 1:055ae04a8003 | 34 | if(bTipka->LStatus() == false) { |
| mario_meh | 1:055ae04a8003 | 35 | kontrola = 0; |
| mario_meh | 1:055ae04a8003 | 36 | } |
| mario_meh | 0:4cac97044e74 | 37 | |
| mario_meh | 0:4cac97044e74 | 38 | //--------------------------------------------------IR argumenti |
| mario_meh | 1:055ae04a8003 | 39 | |
| mario_meh | 1:055ae04a8003 | 40 | //--------------------------------------------------Provjera Servo C90 |
| mario_meh | 1:055ae04a8003 | 41 | t.start(); |
| mario_meh | 1:055ae04a8003 | 42 | sMotor.write_us(2000); |
| mario_meh | 1:055ae04a8003 | 43 | t.stop(); |
| mario_meh | 1:055ae04a8003 | 44 | pc.printf("%f\n\r", t.read()); |
| mario_meh | 1:055ae04a8003 | 45 | wait_ms(1000); |
| mario_meh | 1:055ae04a8003 | 46 | t.reset(); |
| mario_meh | 1:055ae04a8003 | 47 | t.start(); |
| mario_meh | 1:055ae04a8003 | 48 | sMotor.write_us(0); |
| mario_meh | 1:055ae04a8003 | 49 | t.stop(); |
| mario_meh | 1:055ae04a8003 | 50 | pc.printf("%f\n\r", t.read()); |
| mario_meh | 1:055ae04a8003 | 51 | wait_ms(1000); |
| mario_meh | 1:055ae04a8003 | 52 | t.reset(); |
| mario_meh | 1:055ae04a8003 | 53 | t.start(); |
| mario_meh | 1:055ae04a8003 | 54 | sMotor.write_us(3000); |
| mario_meh | 1:055ae04a8003 | 55 | t.stop(); |
| mario_meh | 1:055ae04a8003 | 56 | pc.printf("%f\n\r", t.read()); |
| mario_meh | 1:055ae04a8003 | 57 | wait_ms(1000); |
| mario_meh | 1:055ae04a8003 | 58 | t.reset(); |
| mario_meh | 1:055ae04a8003 | 59 | t.start(); |
| mario_meh | 1:055ae04a8003 | 60 | sMotor.write_us(1000); |
| mario_meh | 1:055ae04a8003 | 61 | t.stop(); |
| mario_meh | 1:055ae04a8003 | 62 | pc.printf("%f\n\r", t.read()); |
| mario_meh | 1:055ae04a8003 | 63 | wait_ms(1000); |
| mario_meh | 1:055ae04a8003 | 64 | sMotor.Disable(); |
| mario_meh | 1:055ae04a8003 | 65 | //-------------------------------------------------Gotovo Provjera Servo C90 |
| mario_meh | 1:055ae04a8003 | 66 | |
| mario_meh | 1:055ae04a8003 | 67 | //--------------------------------------------------Unipolarni steper |
| mario_meh | 1:055ae04a8003 | 68 | Steper *unipolar = new Steper(); |
| mario_meh | 1:055ae04a8003 | 69 | |
| mario_meh | 1:055ae04a8003 | 70 | unipolar->u_poz.u_krenuo = 1; // Treba biti 1(0) |
| mario_meh | 1:055ae04a8003 | 71 | unipolar->u_poz.u_stao = 0; // Treba biti 0(1) |
| mario_meh | 1:055ae04a8003 | 72 | unipolar->Brzina(4000); // < brzina = brze i krace |
| mario_meh | 1:055ae04a8003 | 73 | unipolar->UEnable(); // Pokreni umotor |
| mario_meh | 1:055ae04a8003 | 74 | //--------------------------------------------------Gotovo Unipolarni steper |
| mario_meh | 1:055ae04a8003 | 75 | |
| mario_meh | 1:055ae04a8003 | 76 | //-------------------------------------------------- IR Receiver |
| mario_meh | 0:4cac97044e74 | 77 | pinIn.enableIRIn(); // Start the receiver |
| mario_meh | 0:4cac97044e74 | 78 | decode_results results; |
| mario_meh | 0:4cac97044e74 | 79 | |
| mario_meh | 0:4cac97044e74 | 80 | int IR_REMOTE = 1; |
| mario_meh | 0:4cac97044e74 | 81 | |
| mario_meh | 0:4cac97044e74 | 82 | while(IR_REMOTE == 1) { |
| mario_meh | 0:4cac97044e74 | 83 | if (pinIn.decode(&results)) { |
| mario_meh | 0:4cac97044e74 | 84 | uint32_t value = results.value; |
| mario_meh | 0:4cac97044e74 | 85 | remote[0] = (value); |
| mario_meh | 0:4cac97044e74 | 86 | remote[1] = (value) >> 8; |
| mario_meh | 0:4cac97044e74 | 87 | remote[2] = (value) >> 16; |
| mario_meh | 0:4cac97044e74 | 88 | remote[3] = (value) >> 24; |
| mario_meh | 0:4cac97044e74 | 89 | |
| mario_meh | 0:4cac97044e74 | 90 | i2c.write(addr,remote, 4); |
| mario_meh | 0:4cac97044e74 | 91 | pinIn.resume(); // Receive the next value |
| mario_meh | 0:4cac97044e74 | 92 | } |
| mario_meh | 0:4cac97044e74 | 93 | wait(0.1); |
| mario_meh | 0:4cac97044e74 | 94 | } |
| mario_meh | 0:4cac97044e74 | 95 | //-----------------------------------------------------gotov iR |
| mario_meh | 0:4cac97044e74 | 96 | |
| mario_meh | 0:4cac97044e74 | 97 | //------------------------------------------isprobavam joystick |
| mario_meh | 0:4cac97044e74 | 98 | // Pozovi Joystick |
| mario_meh | 0:4cac97044e74 | 99 | |
| mario_meh | 1:055ae04a8003 | 100 | JoysKompas *data = new JoysKompas; |
| mario_meh | 1:055ae04a8003 | 101 | Joystick *joys = new Joystick(data); |
| mario_meh | 1:055ae04a8003 | 102 | joys->YEnable(); |
| mario_meh | 1:055ae04a8003 | 103 | |
| mario_meh | 1:055ae04a8003 | 104 | while(1) { |
| mario_meh | 1:055ae04a8003 | 105 | switch(data->vertikala) { |
| mario_meh | 0:4cac97044e74 | 106 | case 0: |
| mario_meh | 1:055ae04a8003 | 107 | serial.printf("Gore: %i\r\n", data->vertikala); |
| mario_meh | 0:4cac97044e74 | 108 | break; |
| mario_meh | 0:4cac97044e74 | 109 | case 1: |
| mario_meh | 1:055ae04a8003 | 110 | serial.printf("Dolje: %i\r\n", data->vertikala); |
| mario_meh | 0:4cac97044e74 | 111 | break; |
| mario_meh | 1:055ae04a8003 | 112 | } |
| mario_meh | 1:055ae04a8003 | 113 | |
| mario_meh | 0:4cac97044e74 | 114 | } |
| mario_meh | 1:055ae04a8003 | 115 | |
| mario_meh | 0:4cac97044e74 | 116 | //----------------------------------------------gotov joystick |
| mario_meh | 0:4cac97044e74 | 117 | |
| mario_meh | 0:4cac97044e74 | 118 | //-----------------------------------------------------svjetlo |
| mario_meh | 0:4cac97044e74 | 119 | //led = 1; |
| mario_meh | 0:4cac97044e74 | 120 | //-------------------------------------------------end svjetlo |
| mario_meh | 0:4cac97044e74 | 121 | |
| mario_meh | 1:055ae04a8003 | 122 | } |