NHK2021_ikarashiSolenoidValve

Dependents:   NHK2021_ikarashiSV_code NHK2021_ikarashiSV_code_withservo 2021NHK_B_syudo

Committer:
ikarashikota
Date:
Thu Oct 21 16:06:55 2021 +0000
Revision:
4:6d421db6e727
Parent:
3:1fc2008f3a07
Child:
5:1ef248a66820
:-)

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 4:6d421db6e727 19 //投げる
ikarashikota 3:1fc2008f3a07 20 port_a = 0;
ikarashikota 3:1fc2008f3a07 21 port_b = 1;
ikarashikota 3:1fc2008f3a07 22 port_c = 0;
ikarashikota 3:1fc2008f3a07 23 port_d = 1;
ikarashikota 0:2b253298d427 24 solenoid_status = 2;
ikarashikota 0:2b253298d427 25 break;
ikarashikota 4:6d421db6e727 26 case 2:
ikarashikota 0:2b253298d427 27 //戻る
ikarashikota 3:1fc2008f3a07 28 port_c = 1;
ikarashikota 3:1fc2008f3a07 29 port_d = 0;
ikarashikota 4:6d421db6e727 30 //wait(0.3);
ikarashikota 0:2b253298d427 31
ikarashikota 3:1fc2008f3a07 32 port_a = 1;
ikarashikota 3:1fc2008f3a07 33 port_b = 0;
ikarashikota 0:2b253298d427 34 solenoid_status = 0;
ikarashikota 0:2b253298d427 35 break;
ikarashikota 4:6d421db6e727 36 case 0://禅開放
ikarashikota 4:6d421db6e727 37 port_c = 0;
ikarashikota 4:6d421db6e727 38 port_d = 1;
ikarashikota 4:6d421db6e727 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 1:696f7c0ab1bd 70 ikarashiSV slv(PC_7,PB_10,PB_4,PB_5);
ikarashikota 0:2b253298d427 71
ikarashikota 1:696f7c0ab1bd 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 */