![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Haskovic Nedzad Hadzic Muharem
main.cpp@0:7420c8ee25c3, 2014-05-15 (annotated)
- Committer:
- tim008
- Date:
- Thu May 15 16:04:40 2014 +0000
- Revision:
- 0:7420c8ee25c3
GRUPA6_LV9_zadatak2_tim008
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim008 | 0:7420c8ee25c3 | 1 | #include "mbed.h" |
tim008 | 0:7420c8ee25c3 | 2 | #include "sMotor.h" |
tim008 | 0:7420c8ee25c3 | 3 | |
tim008 | 0:7420c8ee25c3 | 4 | |
tim008 | 0:7420c8ee25c3 | 5 | Serial pc(USBTX, USBRX); |
tim008 | 0:7420c8ee25c3 | 6 | sMotor motor(dp9, dp10, dp11, dp13); |
tim008 | 0:7420c8ee25c3 | 7 | int brzina=800; |
tim008 | 0:7420c8ee25c3 | 8 | bool on_off=true; |
tim008 | 0:7420c8ee25c3 | 9 | int smjer=1; |
tim008 | 0:7420c8ee25c3 | 10 | void meni() |
tim008 | 0:7420c8ee25c3 | 11 | { |
tim008 | 0:7420c8ee25c3 | 12 | pc.printf("A - Postavi osovinu motora (0-360 stepeni) \n\r"); |
tim008 | 0:7420c8ee25c3 | 13 | pc.printf("S - Promjeni brzinu kretanja \n\r"); |
tim008 | 0:7420c8ee25c3 | 14 | pc.printf("D - Promjeni smjer kretanja \n\r"); |
tim008 | 0:7420c8ee25c3 | 15 | pc.printf("F - Pokreni/zaustavi motor \n\r"); |
tim008 | 0:7420c8ee25c3 | 16 | } |
tim008 | 0:7420c8ee25c3 | 17 | |
tim008 | 0:7420c8ee25c3 | 18 | void pali_gasi() |
tim008 | 0:7420c8ee25c3 | 19 | { |
tim008 | 0:7420c8ee25c3 | 20 | if(on_off) |
tim008 | 0:7420c8ee25c3 | 21 | { |
tim008 | 0:7420c8ee25c3 | 22 | motor.step(512,smjer,brzina); |
tim008 | 0:7420c8ee25c3 | 23 | pc.printf("Motor je upaljen.\n\r"); |
tim008 | 0:7420c8ee25c3 | 24 | } |
tim008 | 0:7420c8ee25c3 | 25 | else |
tim008 | 0:7420c8ee25c3 | 26 | { |
tim008 | 0:7420c8ee25c3 | 27 | motor.step(512,smjer,0); |
tim008 | 0:7420c8ee25c3 | 28 | pc.printf("Motor je ugasen.\n\r"); |
tim008 | 0:7420c8ee25c3 | 29 | |
tim008 | 0:7420c8ee25c3 | 30 | } |
tim008 | 0:7420c8ee25c3 | 31 | } |
tim008 | 0:7420c8ee25c3 | 32 | |
tim008 | 0:7420c8ee25c3 | 33 | void obrnutismjer() |
tim008 | 0:7420c8ee25c3 | 34 | { |
tim008 | 0:7420c8ee25c3 | 35 | motor.step(512,smjer,brzina); |
tim008 | 0:7420c8ee25c3 | 36 | |
tim008 | 0:7420c8ee25c3 | 37 | } |
tim008 | 0:7420c8ee25c3 | 38 | |
tim008 | 0:7420c8ee25c3 | 39 | int main() |
tim008 | 0:7420c8ee25c3 | 40 | { |
tim008 | 0:7420c8ee25c3 | 41 | char a; |
tim008 | 0:7420c8ee25c3 | 42 | while (1) |
tim008 | 0:7420c8ee25c3 | 43 | { |
tim008 | 0:7420c8ee25c3 | 44 | |
tim008 | 0:7420c8ee25c3 | 45 | meni(); |
tim008 | 0:7420c8ee25c3 | 46 | a=pc.getc(); |
tim008 | 0:7420c8ee25c3 | 47 | if(a=='A') |
tim008 | 0:7420c8ee25c3 | 48 | { |
tim008 | 0:7420c8ee25c3 | 49 | int ugao; |
tim008 | 0:7420c8ee25c3 | 50 | pc.printf("\nNavedite ugao pomjeranja motora: \n\r"); |
tim008 | 0:7420c8ee25c3 | 51 | pc.scanf("%d", &ugao); |
tim008 | 0:7420c8ee25c3 | 52 | if ( ugao > 0 ) |
tim008 | 0:7420c8ee25c3 | 53 | motor.step(512 / 360.0 * (ugao % 360), smjer, brzina); |
tim008 | 0:7420c8ee25c3 | 54 | else |
tim008 | 0:7420c8ee25c3 | 55 | motor.step(512 / 360.0 * (ugao % 360), 1 - smjer, brzina); |
tim008 | 0:7420c8ee25c3 | 56 | } |
tim008 | 0:7420c8ee25c3 | 57 | if(a=='S') |
tim008 | 0:7420c8ee25c3 | 58 | { |
tim008 | 0:7420c8ee25c3 | 59 | pc.printf("\nTrenutna brzina: %d\n\r", brzina); |
tim008 | 0:7420c8ee25c3 | 60 | pc.printf("\nNova brzina: \n\r"); |
tim008 | 0:7420c8ee25c3 | 61 | pc.scanf("%d",&brzina); |
tim008 | 0:7420c8ee25c3 | 62 | motor.step(512,smjer,brzina); |
tim008 | 0:7420c8ee25c3 | 63 | |
tim008 | 0:7420c8ee25c3 | 64 | } |
tim008 | 0:7420c8ee25c3 | 65 | if(a=='D') |
tim008 | 0:7420c8ee25c3 | 66 | { |
tim008 | 0:7420c8ee25c3 | 67 | if (smjer==0) |
tim008 | 0:7420c8ee25c3 | 68 | smjer=1; |
tim008 | 0:7420c8ee25c3 | 69 | else |
tim008 | 0:7420c8ee25c3 | 70 | smjer=0; |
tim008 | 0:7420c8ee25c3 | 71 | obrnutismjer(); |
tim008 | 0:7420c8ee25c3 | 72 | pc.printf("\nPromjena smjera. \n\r"); |
tim008 | 0:7420c8ee25c3 | 73 | |
tim008 | 0:7420c8ee25c3 | 74 | } |
tim008 | 0:7420c8ee25c3 | 75 | |
tim008 | 0:7420c8ee25c3 | 76 | if(a=='F') |
tim008 | 0:7420c8ee25c3 | 77 | { |
tim008 | 0:7420c8ee25c3 | 78 | on_off=!on_off; |
tim008 | 0:7420c8ee25c3 | 79 | pali_gasi(); |
tim008 | 0:7420c8ee25c3 | 80 | } |
tim008 | 0:7420c8ee25c3 | 81 | |
tim008 | 0:7420c8ee25c3 | 82 | |
tim008 | 0:7420c8ee25c3 | 83 | } |
tim008 | 0:7420c8ee25c3 | 84 | |
tim008 | 0:7420c8ee25c3 | 85 | |
tim008 | 0:7420c8ee25c3 | 86 | } |
tim008 | 0:7420c8ee25c3 | 87 |