NervousPuppySprintTwo
Dependencies: C12832_lcd Servo USBHost mbed
Fork of USBHostSerial_HelloWorld by
Diff: main.cpp
- Revision:
- 8:eaae889bc6eb
- Parent:
- 7:3b14ddcf6d8e
- Child:
- 9:ea3cfd16b4d9
diff -r 3b14ddcf6d8e -r eaae889bc6eb main.cpp --- a/main.cpp Mon Mar 02 15:20:18 2015 +0000 +++ b/main.cpp Tue Mar 03 19:32:09 2015 +0000 @@ -3,6 +3,12 @@ #include "C12832_lcd.h" #include "Servo.h" +#define RCOUNTERTIME if(posx<=1500) posx+=1; +#define RTIME if(posx>=500) posx-=1; +#define TILTBACK if(posy>=500) posy-=1; +#define TILTFORW if(posy<=1000) posy+=1; +#define TEMPORARY rotate.SetPosition(posx); tilt.SetPosition(posy); + DigitalOut led1(LED1); DigitalOut led3(LED3); Serial pc(USBTX, USBRX); @@ -14,37 +20,43 @@ AnalogIn ainRight(p16); Mutex rx_mutex; +Mutex tiltserv; +Mutex rotateserv; +int posx = 1000,posy = 750; + +void rotate_servo(int x); + +void tild_thread(void const *args) +{ + while (true) { + tiltserv.lock(); + tilt.SetPosition(posy); + tiltserv.unlock(); + } +} + +void rotate_thread(void const *args) +{ + while (true) { + rotateserv.lock(); + rotate.SetPosition(posx); + rotateserv.unlock(); + } +} int main() { - int pos = 1000; - tilt.Enable(1000,20000); + tilt.Enable(750,20000); + rotate.Enable(1000,20000); + Thread thr1(tild_thread); + Thread thr2(rotate_thread); lcd.cls(); char buffer[128]; - + rotate.SetPosition(1000); + tilt.SetPosition(750); + while (true) - { - for(pos=1000;pos<=1250;pos+=1) - { - tilt.SetPosition(pos); - lcd.cls(); - lcd.printf(" %d ", pos); - //wait(0.5); - } - - for(pos=1250;pos>=1000;pos-=1) - { - tilt.SetPosition(pos); - lcd.printf(" %d ", pos); - //wait(0.5); - } - - } - - - -/* while (true) { if(pc.readable()) { @@ -56,7 +68,15 @@ lcd.printf(buffer); } int x=atoi(buffer); - switch (x) + + rotate_servo(x); + } +} + + + +void rotate_servo(int x){ + switch (x) { case 0: lcd.cls(); @@ -69,51 +89,79 @@ lcd.cls(); lcd.locate(0,1); lcd.printf("Right"); - //thread servo right + RCOUNTERTIME; + break; case 2: lcd.cls(); lcd.locate(0,1); lcd.printf("down & right"); - + RCOUNTERTIME; + TILTFORW; + break; case 3: lcd.cls(); lcd.locate(0,1); lcd.printf("down"); + TILTFORW; + break; case 4: lcd.cls(); lcd.locate(0,1); - lcd.printf("Ddown & left"); + lcd.printf("Down & left"); + RTIME; + TILTFORW; + break; case 5: lcd.cls(); lcd.locate(0,1); lcd.printf("left"); + RTIME; + + + break; case 6: lcd.cls(); lcd.locate(0,1); lcd.printf("up & left"); + RTIME; + TILTBACK; + + + break; case 7: lcd.cls(); lcd.locate(0,1); lcd.printf("up"); + TILTBACK; + + + break; case 8: lcd.cls(); lcd.locate(0,1); - lcd.printf("up & left"); + lcd.printf("up & right"); + TILTBACK; + RCOUNTERTIME; + + break; + } - } */ -} + + } + +