tim007 tim007
/
LV9-G6-T007-Zadatak2
haris spahic faris dzafic
main.cpp@0:e05d02767558, 2014-05-15 (annotated)
- Committer:
- tim007
- Date:
- Thu May 15 16:03:09 2014 +0000
- Revision:
- 0:e05d02767558
lv9-zad2-tim007-grupa6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim007 | 0:e05d02767558 | 1 | #include "mbed.h" |
tim007 | 0:e05d02767558 | 2 | #include "sMotor.h" |
tim007 | 0:e05d02767558 | 3 | |
tim007 | 0:e05d02767558 | 4 | Serial pc(USBTX, USBRX); |
tim007 | 0:e05d02767558 | 5 | sMotor motor(dp13, dp11, dp10, dp9); |
tim007 | 0:e05d02767558 | 6 | |
tim007 | 0:e05d02767558 | 7 | int speed = 1200; |
tim007 | 0:e05d02767558 | 8 | int numstep= 512; |
tim007 | 0:e05d02767558 | 9 | bool start=false; |
tim007 | 0:e05d02767558 | 10 | |
tim007 | 0:e05d02767558 | 11 | int smjer=0; //0 - desno |
tim007 | 0:e05d02767558 | 12 | |
tim007 | 0:e05d02767558 | 13 | int main() { |
tim007 | 0:e05d02767558 | 14 | |
tim007 | 0:e05d02767558 | 15 | pc.printf("1- pokreni/zaustavi \n\r"); |
tim007 | 0:e05d02767558 | 16 | pc.printf("2- promjeni smjer(0-desno,1-lijevo) \n\r"); |
tim007 | 0:e05d02767558 | 17 | pc.printf("3- postavljanje polozaja \n\r"); |
tim007 | 0:e05d02767558 | 18 | pc.printf("4- promjeni brzinu \n\r"); |
tim007 | 0:e05d02767558 | 19 | while (1) { |
tim007 | 0:e05d02767558 | 20 | if(start) motor.step(numstep,smjer,speed); |
tim007 | 0:e05d02767558 | 21 | char c = pc.getc(); |
tim007 | 0:e05d02767558 | 22 | if (c == '1' && start == false ) start = true; |
tim007 | 0:e05d02767558 | 23 | else if(c == '1' && start == true) start = false; |
tim007 | 0:e05d02767558 | 24 | else if(c == '2' && smjer == 0)smjer = 1; |
tim007 | 0:e05d02767558 | 25 | else if(c == '2' && smjer == 1) smjer = 0; |
tim007 | 0:e05d02767558 | 26 | else if(c == '3'){ |
tim007 | 0:e05d02767558 | 27 | int ugao; |
tim007 | 0:e05d02767558 | 28 | pc.printf("\n\r"); |
tim007 | 0:e05d02767558 | 29 | pc.printf("Postavi polozaj: \n\r"); |
tim007 | 0:e05d02767558 | 30 | pc.scanf("%d", &ugao); |
tim007 | 0:e05d02767558 | 31 | numstep = int(512/360*(ugao%360)); |
tim007 | 0:e05d02767558 | 32 | motor.step(numstep,smjer,speed); |
tim007 | 0:e05d02767558 | 33 | numstep = 512; |
tim007 | 0:e05d02767558 | 34 | } |
tim007 | 0:e05d02767558 | 35 | else if (c == '4') { |
tim007 | 0:e05d02767558 | 36 | pc.printf("Nova brzina: \n\r"); |
tim007 | 0:e05d02767558 | 37 | pc.scanf("%d",&speed); |
tim007 | 0:e05d02767558 | 38 | } |
tim007 | 0:e05d02767558 | 39 | else continue; |
tim007 | 0:e05d02767558 | 40 | |
tim007 | 0:e05d02767558 | 41 | } |
tim007 | 0:e05d02767558 | 42 | } |