お盆用コードだよ

Dependencies:   Servo mbed-rtos mbed

main.cpp

Committer:
Hatter
Date:
2014-06-24
Revision:
0:72dbc49bd254
Child:
1:17b3afbf9278

File content as of revision 0:72dbc49bd254:

/*
* Servo motor program for OBON  by Tomoki Hokida
*
* Use rtos in this program
*
* RTOSをバリバリ使用しているのであしあらず
* サーボを4つ使うことになったらSERVO_4をdefineしましょう
*/

#include "mbed.h"
#include "Servo.h"
#include "rtos.h"

#define DEFAULT_R 50
#define DEFAULT_L 50
#define DEFAULT_U 50
#define DEFAULT_D 50

DigitalOut led1(LED1);
DigitalOut led2(LED2);

#ifdef SERVO_4
DigitalOut led3(LED3);
DigitalOut led4(LED4);
#endif

DigitalIn swU(p17);
DigitalIn swD(p18);
DigitalIn swR(p19);
DigitalIn swL(p20);

Servo obonU(p21);
Servo obonR(p22);

#ifdef SERVO_4
Servo obonD(p23);
Servo obonL(p24);
#endif

void obonThreadR(void const *argument){

    for(int j=DEFAULT_R;;){

        obonR = j/100.0;
        
         if((!swR)&&(j<100.0)){j++;}
         if((!swL)&&(j>0)){j--;}
         
         led1 = !led1;
         
        Thread::wait(10);
    }
}

void obonThreadU(void const *argument){
    for(int k=DEFAULT_U; ;){
        
        obonU = k/100.0;
        
        if((!swU)&&(k<100.0)){k++;}
        if((!swD)&&(k>0)){k--;}
        
        led2 = !led2;
        
        Thread::wait(10);
    }
}

#ifdef SERVO_4

void obonThreadL(void const *argument){
    for(int i=DEFAULT_L;;){
        
        obonL = i/100.0;
        
        if((!swL)&&(i<100.0)){i++;}
        if((!swR)&&(i>0)){i--;}
        
        led3 = !led3;
        
        Thread::wait(10);
    }
}

void obonThreadD(void const *argument){
    for(int l=DEFAULT_D;;){
        
        obonL = l/100.0;
        
        if((!swD)&&(l<=100.0)){l++;}
        if((!swU)&&(l>=0)){l--;}
        
        led4 = !led4;
        
        Thread::wait(10);
    }
}


#endif

int main() {
    
    swU.mode(PullUp);
    swD.mode(PullUp);
    swL.mode(PullUp);
    swR.mode(PullUp);
    
    Thread thread1(obonThreadU);
    Thread thread2(obonThreadR);
    
    #ifdef SERVO_4
        
    Thread thread3(obonThreadD);
    Thread thread4(obonThreadL);
    
    #endif
    for(;;);

}