Nurbol Nurdaulet / Mbed 2 deprecated state_machine

Dependencies:   mbed

main.cpp

Committer:
Nurbol
Date:
2011-11-24
Revision:
0:079cf37f39ca

File content as of revision 0:079cf37f39ca:

#include "mbed.h"

static int state(0);

int main() {
    while(1) {
    switch(state)
    {
        case 0:
             servo_4.pulsewidth_us(1000 + (25 * 1000) / 90);
             servo_0.pulsewidth_us(1000 + (0 * 1000) / 90); 
             servo_5.pulsewidth_us(1000 + (0 * 1000) / 90); 
             Position1p_1 = 1;
             Position1p_2 = 0;
             Position2p_1 = 1;
             Position2p_2 = 0;
             if(counter1p == 1){
                state = 1;
             }
             if(counter2p == 1){
                state = 4;
             }
             break;
        case 1:
             servo_4.pulsewidth_us(0);
             servo_0.pulsewidth_us(1000 + (200 * 1000) / 90); 
             wait(1);
             Position1p_1 = 0;
             Position1p_2 = 1;
             if(Position1p_2 == 1){
                state = 2;
             }
             break;
        case 2:
             servo_4.pulsewidth_us(1000 + (25 * 1000) / 90);
             if(counter1p = 1){
                state = 3;
             }
             break;
        case 3:
             servo_4.pulsewidth_us(0);
             if(SW1p == 1){
                state = 0;
             }
             break;
        case 4:
             servo_4.pulsewidth_us(0);
             servo_5.pulsewidth_us(1000 + (200 * 1000) / 90);
             wait(1);
             Position2p_1 = 0;
             Position2p_2 = 1;
             if(Position2p_2 == 1){
                state = 5;
             }
             break;
        case 5:
             servo_4.pulsewidth_us(1000 + (25 * 1000) / 90);
             if(counter2p == 1){
                state = 6;
             }
             break;
        case 6:
             servo_4.pulsewidth_us(0);
             if(SW2p == 1){
                state = 0;
             }
             break;         
    }   
   }
}