お盆用コードだよ
Dependencies: Servo mbed-rtos mbed
Revision 2:0edba6ddfd48, committed 2014-06-28
- Comitter:
- Hatter
- Date:
- Sat Jun 28 07:08:59 2014 +0000
- Parent:
- 1:17b3afbf9278
- Commit message:
- RTOS??????????????????
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 17b3afbf9278 -r 0edba6ddfd48 main.cpp --- a/main.cpp Tue Jun 24 09:05:13 2014 +0000 +++ b/main.cpp Sat Jun 28 07:08:59 2014 +0000 @@ -1,7 +1,7 @@ /* * Servo motor program for OBON by Tomoki Hokida * -* Use rtos in this program +* Use RTOS in this program * * RTOSをバリバリ使用しているのであしあらず * サーボを4つ使うことになったらSERVO_4をdefineしましょう @@ -16,7 +16,7 @@ #define DEFAULT_U 50 #define DEFAULT_D 50 -//#define SERVO_4 +#define SERVO_4 DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -26,27 +26,36 @@ DigitalOut led4(LED4); #endif -DigitalIn swU(p17); -DigitalIn swD(p18); -DigitalIn swR(p19); -DigitalIn swL(p20); +DigitalIn sw[4] = {p17, p19, p18, p20}; -Servo obonU(p21); -Servo obonR(p22); +//DigitalIn swU(p17); +//DigitalIn swD(p18); +//DigitalIn swR(p19); +//DigitalIn swL(p20); +//Servo obonU(p21); +//Servo obonR(p22); +//Servo obonD(p23); +//Servo obonL(p24); + #ifdef SERVO_4 -Servo obonD(p23); -Servo obonL(p24); + +Servo obon[4] = { p21, p22, p23, p24}; + +#else + +Servo obon[2] = {p21,p22}; + #endif void obonThreadR(void const *argument){ for(int j=DEFAULT_R;;){ - obonR = j/100.0; + obon[1] = j/100.0; - if((!swR)&&(j<100.0)){j++;} - if((!swL)&&(j>0)){j--;} + if((!sw[1])&&(j<100.0)){j++;} + if((!sw[3])&&(j>0)){j--;} led1 = !led1; @@ -57,10 +66,10 @@ void obonThreadU(void const *argument){ for(int k=DEFAULT_U; ;){ - obonU = k/100.0; + obon[0] = k/100.0; - if((!swU)&&(k<100.0)){k++;} - if((!swD)&&(k>0)){k--;} + if((!sw[0])&&(k<100.0)){k++;} + if((!sw[2])&&(k>0)){k--;} led2 = !led2; @@ -73,10 +82,10 @@ void obonThreadL(void const *argument){ for(int i=DEFAULT_L;;){ - obonL = i/100.0; + obon[3] = i/100.0; - if((!swL)&&(i<100.0)){i++;} - if((!swR)&&(i>0)){i--;} + if((!sw[3])&&(i<100.0)){i++;} + if((!sw[1])&&(i>0)){i--;} led3 = !led3; @@ -87,36 +96,35 @@ void obonThreadD(void const *argument){ for(int l=DEFAULT_D;;){ - obonL = l/100.0; + obon[2] = l/100.0; - if((!swD)&&(l<=100.0)){l++;} - if((!swU)&&(l>=0)){l--;} + if((!sw[2])&&(l<=100.0)){l++;} + if((!sw[1])&&(l>=0)){l--;} led4 = !led4; Thread::wait(10); } } - - #endif int main() { - swU.mode(PullUp); - swD.mode(PullUp); - swL.mode(PullUp); - swR.mode(PullUp); + sw[0].mode(PullUp); + sw[1].mode(PullUp); + sw[2].mode(PullUp); + sw[3].mode(PullUp); + Thread thread1(obonThreadU); Thread thread2(obonThreadR); - #ifdef SERVO_4 +#ifdef SERVO_4 Thread thread3(obonThreadD); Thread thread4(obonThreadL); - - #endif + +#endif for(;;); } \ No newline at end of file