NHK2021_ikarashiSolenoidValve

Dependents:   NHK2021_ikarashiSV_code NHK2021_ikarashiSV_code_withservo 2021NHK_B_syudo

Committer:
ikarashikota
Date:
Mon Oct 11 07:48:12 2021 +0000
Revision:
0:2b253298d427
Child:
1:696f7c0ab1bd
Child:
2:d08346d0178a
NHK2021_ikarashiSolenoidValve

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ikarashikota 0:2b253298d427 1 #include "ikarashiSV.h"
ikarashikota 0:2b253298d427 2
ikarashikota 0:2b253298d427 3 ikarashiSV::ikarashiSV(PinName pin_a,PinName pin_b,PinName pin_c,PinName pin_d):
ikarashikota 0:2b253298d427 4 port_a(pin_a), port_b(pin_b), port_c(pin_c), port_d(pin_d)
ikarashikota 0:2b253298d427 5 {
ikarashikota 0:2b253298d427 6 state = 0;
ikarashikota 0:2b253298d427 7 solenoid_status = 0;
ikarashikota 0:2b253298d427 8 }
ikarashikota 0:2b253298d427 9
ikarashikota 0:2b253298d427 10 void ikarashiSV::add_state()
ikarashikota 0:2b253298d427 11 {
ikarashikota 0:2b253298d427 12 state++;
ikarashikota 0:2b253298d427 13 }
ikarashikota 0:2b253298d427 14
ikarashikota 0:2b253298d427 15 void ikarashiSV::solenoid(int _state)
ikarashikota 0:2b253298d427 16 {
ikarashikota 0:2b253298d427 17 switch(_state) {
ikarashikota 0:2b253298d427 18 case 1:
ikarashikota 0:2b253298d427 19 //下だけ上がる
ikarashikota 0:2b253298d427 20 port_a = 0;
ikarashikota 0:2b253298d427 21 port_b = 1;
ikarashikota 0:2b253298d427 22 solenoid_status = 1;
ikarashikota 0:2b253298d427 23 break;
ikarashikota 0:2b253298d427 24 case 2:
ikarashikota 0:2b253298d427 25 //投げる
ikarashikota 0:2b253298d427 26 port_c = 1;
ikarashikota 0:2b253298d427 27 port_d = 0;
ikarashikota 0:2b253298d427 28 solenoid_status = 2;
ikarashikota 0:2b253298d427 29 break;
ikarashikota 0:2b253298d427 30 case 0:
ikarashikota 0:2b253298d427 31 //戻る
ikarashikota 0:2b253298d427 32 port_c = 0;
ikarashikota 0:2b253298d427 33 port_d = 1;
ikarashikota 0:2b253298d427 34 wait(0.3);
ikarashikota 0:2b253298d427 35
ikarashikota 0:2b253298d427 36 port_a = 1;
ikarashikota 0:2b253298d427 37 port_b = 0;
ikarashikota 0:2b253298d427 38 solenoid_status = 0;
ikarashikota 0:2b253298d427 39 break;
ikarashikota 0:2b253298d427 40 }
ikarashikota 0:2b253298d427 41 }
ikarashikota 0:2b253298d427 42
ikarashikota 0:2b253298d427 43 void ikarashiSV::solenoid_show()
ikarashikota 0:2b253298d427 44 {
ikarashikota 0:2b253298d427 45 switch(solenoid_status) {
ikarashikota 0:2b253298d427 46 case 1:
ikarashikota 0:2b253298d427 47 printf("1:push\n\r");
ikarashikota 0:2b253298d427 48 break;
ikarashikota 0:2b253298d427 49 case 2:
ikarashikota 0:2b253298d427 50 printf("\t2:push\n\r");
ikarashikota 0:2b253298d427 51 break;
ikarashikota 0:2b253298d427 52 case 0:
ikarashikota 0:2b253298d427 53 printf("1:pull 2:pull\n\r");
ikarashikota 0:2b253298d427 54 break;
ikarashikota 0:2b253298d427 55 }
ikarashikota 0:2b253298d427 56 }
ikarashikota 0:2b253298d427 57
ikarashikota 0:2b253298d427 58 int ikarashiSV::state_show()
ikarashikota 0:2b253298d427 59 {
ikarashikota 0:2b253298d427 60 return state;
ikarashikota 0:2b253298d427 61 }
ikarashikota 0:2b253298d427 62
ikarashikota 0:2b253298d427 63 /* サンプルコード
ikarashikota 0:2b253298d427 64
ikarashikota 0:2b253298d427 65 #include "mbed.h"
ikarashikota 0:2b253298d427 66 #include "ikarashiSV.h"
ikarashikota 0:2b253298d427 67
ikarashikota 0:2b253298d427 68 Serial pc(USBTX, USBRX,115200);
ikarashikota 0:2b253298d427 69
ikarashikota 0:2b253298d427 70 ikarashiSV slv(PB_1,PB_2,PB_15,PB_14);
ikarashikota 0:2b253298d427 71
ikarashikota 0:2b253298d427 72 ボタンを押したときor離したときを読み取る定義の仕方
ikarashikota 0:2b253298d427 73 InterruptIn button(USER_BUTTON);
ikarashikota 0:2b253298d427 74
ikarashikota 0:2b253298d427 75 void add()
ikarashikota 0:2b253298d427 76 {
ikarashikota 0:2b253298d427 77 slv.add_state();
ikarashikota 0:2b253298d427 78 }
ikarashikota 0:2b253298d427 79
ikarashikota 0:2b253298d427 80 int main()
ikarashikota 0:2b253298d427 81 {
ikarashikota 0:2b253298d427 82 int val;
ikarashikota 0:2b253298d427 83 while(1) {
ikarashikota 0:2b253298d427 84 button.fall(&add);
ikarashikota 0:2b253298d427 85 val = slv.state_show();
ikarashikota 0:2b253298d427 86 pc.printf("\t\tstate : %d",val);
ikarashikota 0:2b253298d427 87 if(val >= 1) {
ikarashikota 0:2b253298d427 88 slv.solenoid(val%3);
ikarashikota 0:2b253298d427 89 }
ikarashikota 0:2b253298d427 90 slv.solenoid_show();
ikarashikota 0:2b253298d427 91 }
ikarashikota 0:2b253298d427 92 }
ikarashikota 0:2b253298d427 93
ikarashikota 0:2b253298d427 94 */