2021 NHK B

ikarashiSV.cpp

Committer:
ikarashikota
Date:
2021-10-22
Revision:
7:58da8ee2b38d
Parent:
6:256162828e87
Child:
8:f276fe03c43d

File content as of revision 7:58da8ee2b38d:

#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;
            port_c = 0;
            port_d = 1;
            solenoid_status = 1;
            break;
        case 2:
            //戻る
            port_c = 1;
            port_d = 0;
            port_a = 1;
            port_b = 0;
            solenoid_status = 2;
            break;
        case 0://禅開放
            port_c = 0;
            port_d = 1;
            solenoid_status = 0;
            break;
    }
}

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

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


ikarashiSV2::ikarashiSV2(PinName pin_e, PinName pin_f):
    port_e(pin_e),port_f(pin_f)
{
    solenoid_status2 = 0;
}

void ikarashiSV2::solenoid(int _state2)
{
    switch(_state2) {
        case 1:
            port_e = 0;
            port_f = 1;
            solenoid_status2 = 1;
            break;
        case 0;
            port_e = 1;
            port_f = 0;
            solenoid_status2 = 0;
            break;
    }
}

void ikarashiSV2::solenoid_show()
{
    if(solenoid_status2) {
        printf("2:push");
    } else {
        printf("2:pull");
    }
}

/* サンプルコード

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

Serial pc(USBTX, USBRX,115200);

ikarashiSV slv(PC_7,PB_10,PB_4,PB_5);

//ボタンを押したとき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();
    }
}

*/