NHK2021_ikarashiSolenoidValve
Dependents: NHK2021_ikarashiSV_code NHK2021_ikarashiSV_code_withservo 2021NHK_B_syudo
ikarashiSV.cpp@7:58da8ee2b38d, 2021-10-22 (annotated)
- Committer:
- ikarashikota
- Date:
- Fri Oct 22 07:59:13 2021 +0000
- Revision:
- 7:58da8ee2b38d
- Parent:
- 6:256162828e87
- Child:
- 8:f276fe03c43d
add under SV code
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:256162828e87 | 24 | solenoid_status = 1; |
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 | 3:1fc2008f3a07 | 30 | port_a = 1; |
ikarashikota | 3:1fc2008f3a07 | 31 | port_b = 0; |
ikarashikota | 6:256162828e87 | 32 | solenoid_status = 2; |
ikarashikota | 0:2b253298d427 | 33 | break; |
ikarashikota | 4:6d421db6e727 | 34 | case 0://禅開放 |
ikarashikota | 4:6d421db6e727 | 35 | port_c = 0; |
ikarashikota | 4:6d421db6e727 | 36 | port_d = 1; |
ikarashikota | 6:256162828e87 | 37 | solenoid_status = 0; |
ikarashikota | 4:6d421db6e727 | 38 | break; |
ikarashikota | 0:2b253298d427 | 39 | } |
ikarashikota | 0:2b253298d427 | 40 | } |
ikarashikota | 0:2b253298d427 | 41 | |
ikarashikota | 0:2b253298d427 | 42 | void ikarashiSV::solenoid_show() |
ikarashikota | 0:2b253298d427 | 43 | { |
ikarashikota | 0:2b253298d427 | 44 | switch(solenoid_status) { |
ikarashikota | 0:2b253298d427 | 45 | case 1: |
ikarashikota | 7:58da8ee2b38d | 46 | printf("1:push"); |
ikarashikota | 0:2b253298d427 | 47 | break; |
ikarashikota | 0:2b253298d427 | 48 | case 2: |
ikarashikota | 7:58da8ee2b38d | 49 | printf("1:pull"); |
ikarashikota | 0:2b253298d427 | 50 | break; |
ikarashikota | 0:2b253298d427 | 51 | case 0: |
ikarashikota | 7:58da8ee2b38d | 52 | printf("1:open"); |
ikarashikota | 0:2b253298d427 | 53 | break; |
ikarashikota | 0:2b253298d427 | 54 | } |
ikarashikota | 0:2b253298d427 | 55 | } |
ikarashikota | 0:2b253298d427 | 56 | |
ikarashikota | 0:2b253298d427 | 57 | int ikarashiSV::state_show() |
ikarashikota | 0:2b253298d427 | 58 | { |
ikarashikota | 0:2b253298d427 | 59 | return state; |
ikarashikota | 0:2b253298d427 | 60 | } |
ikarashikota | 0:2b253298d427 | 61 | |
ikarashikota | 7:58da8ee2b38d | 62 | |
ikarashikota | 7:58da8ee2b38d | 63 | ikarashiSV2::ikarashiSV2(PinName pin_e, PinName pin_f): |
ikarashikota | 7:58da8ee2b38d | 64 | port_e(pin_e),port_f(pin_f) |
ikarashikota | 7:58da8ee2b38d | 65 | { |
ikarashikota | 7:58da8ee2b38d | 66 | solenoid_status2 = 0; |
ikarashikota | 7:58da8ee2b38d | 67 | } |
ikarashikota | 7:58da8ee2b38d | 68 | |
ikarashikota | 7:58da8ee2b38d | 69 | void ikarashiSV2::solenoid(int _state2) |
ikarashikota | 7:58da8ee2b38d | 70 | { |
ikarashikota | 7:58da8ee2b38d | 71 | switch(_state2) { |
ikarashikota | 7:58da8ee2b38d | 72 | case 1: |
ikarashikota | 7:58da8ee2b38d | 73 | port_e = 0; |
ikarashikota | 7:58da8ee2b38d | 74 | port_f = 1; |
ikarashikota | 7:58da8ee2b38d | 75 | solenoid_status2 = 1; |
ikarashikota | 7:58da8ee2b38d | 76 | break; |
ikarashikota | 7:58da8ee2b38d | 77 | case 0; |
ikarashikota | 7:58da8ee2b38d | 78 | port_e = 1; |
ikarashikota | 7:58da8ee2b38d | 79 | port_f = 0; |
ikarashikota | 7:58da8ee2b38d | 80 | solenoid_status2 = 0; |
ikarashikota | 7:58da8ee2b38d | 81 | break; |
ikarashikota | 7:58da8ee2b38d | 82 | } |
ikarashikota | 7:58da8ee2b38d | 83 | } |
ikarashikota | 7:58da8ee2b38d | 84 | |
ikarashikota | 7:58da8ee2b38d | 85 | void ikarashiSV2::solenoid_show() |
ikarashikota | 7:58da8ee2b38d | 86 | { |
ikarashikota | 7:58da8ee2b38d | 87 | if(solenoid_status2) { |
ikarashikota | 7:58da8ee2b38d | 88 | printf("2:push"); |
ikarashikota | 7:58da8ee2b38d | 89 | } else { |
ikarashikota | 7:58da8ee2b38d | 90 | printf("2:pull"); |
ikarashikota | 7:58da8ee2b38d | 91 | } |
ikarashikota | 7:58da8ee2b38d | 92 | } |
ikarashikota | 7:58da8ee2b38d | 93 | |
ikarashikota | 0:2b253298d427 | 94 | /* サンプルコード |
ikarashikota | 0:2b253298d427 | 95 | |
ikarashikota | 0:2b253298d427 | 96 | #include "mbed.h" |
ikarashikota | 0:2b253298d427 | 97 | #include "ikarashiSV.h" |
ikarashikota | 0:2b253298d427 | 98 | |
ikarashikota | 0:2b253298d427 | 99 | Serial pc(USBTX, USBRX,115200); |
ikarashikota | 0:2b253298d427 | 100 | |
ikarashikota | 1:696f7c0ab1bd | 101 | ikarashiSV slv(PC_7,PB_10,PB_4,PB_5); |
ikarashikota | 0:2b253298d427 | 102 | |
ikarashikota | 1:696f7c0ab1bd | 103 | //ボタンを押したときor離したときを読み取る定義の仕方 |
ikarashikota | 0:2b253298d427 | 104 | InterruptIn button(USER_BUTTON); |
ikarashikota | 0:2b253298d427 | 105 | |
ikarashikota | 0:2b253298d427 | 106 | void add() |
ikarashikota | 0:2b253298d427 | 107 | { |
ikarashikota | 0:2b253298d427 | 108 | slv.add_state(); |
ikarashikota | 0:2b253298d427 | 109 | } |
ikarashikota | 0:2b253298d427 | 110 | |
ikarashikota | 0:2b253298d427 | 111 | int main() |
ikarashikota | 0:2b253298d427 | 112 | { |
ikarashikota | 0:2b253298d427 | 113 | int val; |
ikarashikota | 0:2b253298d427 | 114 | while(1) { |
ikarashikota | 0:2b253298d427 | 115 | button.fall(&add); |
ikarashikota | 0:2b253298d427 | 116 | val = slv.state_show(); |
ikarashikota | 0:2b253298d427 | 117 | pc.printf("\t\tstate : %d",val); |
ikarashikota | 0:2b253298d427 | 118 | if(val >= 1) { |
ikarashikota | 0:2b253298d427 | 119 | slv.solenoid(val%3); |
ikarashikota | 0:2b253298d427 | 120 | } |
ikarashikota | 0:2b253298d427 | 121 | slv.solenoid_show(); |
ikarashikota | 0:2b253298d427 | 122 | } |
ikarashikota | 0:2b253298d427 | 123 | } |
ikarashikota | 0:2b253298d427 | 124 | |
ikarashikota | 0:2b253298d427 | 125 | */ |