2021 NHK B

ikarashiSV.cpp

Committer:
ikarashikota
Date:
2021-10-11
Revision:
0:2b253298d427
Child:
1:696f7c0ab1bd
Child:
2:d08346d0178a

File content as of revision 0:2b253298d427:

#include "ikarashiSV.h"

ikarashiSV::ikarashiSV(PinName pin_a,PinName pin_b,PinName pin_c,PinName pin_d):
    port_a(pin_a), port_b(pin_b), port_c(pin_c), port_d(pin_d)
{
    state = 0;
    solenoid_status = 0;
}

void ikarashiSV::add_state()
{
    state++;
}

void ikarashiSV::solenoid(int _state)
{
    switch(_state) {
        case 1:
            //下だけ上がる
            port_a = 0;
            port_b = 1;
            solenoid_status = 1;
            break;
        case 2:
            //投げる
            port_c = 1;
            port_d = 0;
            solenoid_status = 2;
            break;
        case 0:
            //戻る
            port_c = 0;
            port_d = 1;
            wait(0.3);

            port_a = 1;
            port_b = 0;
            solenoid_status = 0;
            break;
    }
}

void ikarashiSV::solenoid_show()
{
    switch(solenoid_status) {
        case 1:
            printf("1:push\n\r");
            break;
        case 2:
            printf("\t2:push\n\r");
            break;
        case 0:
            printf("1:pull  2:pull\n\r");
            break;
    }
}

int ikarashiSV::state_show()
{
    return state;
}

/* サンプルコード

#include "mbed.h"
#include "ikarashiSV.h"

Serial pc(USBTX, USBRX,115200);

ikarashiSV slv(PB_1,PB_2,PB_15,PB_14);

ボタンを押したときor離したときを読み取る定義の仕方
InterruptIn button(USER_BUTTON);

void add()
{
    slv.add_state();
}

int main()
{
    int val;
    while(1) {
        button.fall(&add);
        val = slv.state_show();
        pc.printf("\t\tstate : %d",val);
        if(val >= 1) {
            slv.solenoid(val%3);
        }
        slv.solenoid_show();
    }
}

*/