NHK2021_ikarashiSolenoidValve
Dependents: NHK2021_ikarashiSV_code NHK2021_ikarashiSV_code_withservo 2021NHK_B_syudo
ikarashiSV.cpp
- Committer:
- ikarashikota
- Date:
- 2021-10-22
- Revision:
- 6:256162828e87
- Parent:
- 5:1ef248a66820
- Child:
- 7:58da8ee2b38d
File content as of revision 6:256162828e87:
#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\n\r"); break; case 2: printf("1:pull\n\r"); break; case 0: printf("1:open\n\r"); break; } } int ikarashiSV::state_show() { return state; } /* サンプルコード #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(); } } */