NHK2021_ikarashiSolenoidValve
Dependents: NHK2021_ikarashiSV_code NHK2021_ikarashiSV_code_withservo 2021NHK_B_syudo
ikarashiSV.cpp@6:256162828e87, 2021-10-22 (annotated)
- Committer:
- ikarashikota
- Date:
- Fri Oct 22 06:36:52 2021 +0000
- Revision:
- 6:256162828e87
- Parent:
- 5:1ef248a66820
- Child:
- 7:58da8ee2b38d
bonnmisu
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 | 0:2b253298d427 | 46 | printf("1:push\n\r"); |
ikarashikota | 0:2b253298d427 | 47 | break; |
ikarashikota | 0:2b253298d427 | 48 | case 2: |
ikarashikota | 5:1ef248a66820 | 49 | printf("1:pull\n\r"); |
ikarashikota | 0:2b253298d427 | 50 | break; |
ikarashikota | 0:2b253298d427 | 51 | case 0: |
ikarashikota | 5:1ef248a66820 | 52 | printf("1:open\n\r"); |
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 | 0:2b253298d427 | 62 | /* サンプルコード |
ikarashikota | 0:2b253298d427 | 63 | |
ikarashikota | 0:2b253298d427 | 64 | #include "mbed.h" |
ikarashikota | 0:2b253298d427 | 65 | #include "ikarashiSV.h" |
ikarashikota | 0:2b253298d427 | 66 | |
ikarashikota | 0:2b253298d427 | 67 | Serial pc(USBTX, USBRX,115200); |
ikarashikota | 0:2b253298d427 | 68 | |
ikarashikota | 1:696f7c0ab1bd | 69 | ikarashiSV slv(PC_7,PB_10,PB_4,PB_5); |
ikarashikota | 0:2b253298d427 | 70 | |
ikarashikota | 1:696f7c0ab1bd | 71 | //ボタンを押したときor離したときを読み取る定義の仕方 |
ikarashikota | 0:2b253298d427 | 72 | InterruptIn button(USER_BUTTON); |
ikarashikota | 0:2b253298d427 | 73 | |
ikarashikota | 0:2b253298d427 | 74 | void add() |
ikarashikota | 0:2b253298d427 | 75 | { |
ikarashikota | 0:2b253298d427 | 76 | slv.add_state(); |
ikarashikota | 0:2b253298d427 | 77 | } |
ikarashikota | 0:2b253298d427 | 78 | |
ikarashikota | 0:2b253298d427 | 79 | int main() |
ikarashikota | 0:2b253298d427 | 80 | { |
ikarashikota | 0:2b253298d427 | 81 | int val; |
ikarashikota | 0:2b253298d427 | 82 | while(1) { |
ikarashikota | 0:2b253298d427 | 83 | button.fall(&add); |
ikarashikota | 0:2b253298d427 | 84 | val = slv.state_show(); |
ikarashikota | 0:2b253298d427 | 85 | pc.printf("\t\tstate : %d",val); |
ikarashikota | 0:2b253298d427 | 86 | if(val >= 1) { |
ikarashikota | 0:2b253298d427 | 87 | slv.solenoid(val%3); |
ikarashikota | 0:2b253298d427 | 88 | } |
ikarashikota | 0:2b253298d427 | 89 | slv.solenoid_show(); |
ikarashikota | 0:2b253298d427 | 90 | } |
ikarashikota | 0:2b253298d427 | 91 | } |
ikarashikota | 0:2b253298d427 | 92 | |
ikarashikota | 0:2b253298d427 | 93 | */ |