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