大季 矢花
/
MB2019_main_alltimes_1123
aa
Switch/Switch.cpp@59:5cd3875fa96a, 2019-11-23 (annotated)
- Committer:
- yabahiro
- Date:
- Sat Nov 23 14:28:20 2019 +0000
- Revision:
- 59:5cd3875fa96a
- Parent:
- 30:8f092276b2ba
aa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
M_souta | 30:8f092276b2ba | 1 | #include "Switch.h" |
M_souta | 30:8f092276b2ba | 2 | |
M_souta | 30:8f092276b2ba | 3 | #include <stdint.h> |
M_souta | 30:8f092276b2ba | 4 | #include "mbed.h" |
M_souta | 30:8f092276b2ba | 5 | |
M_souta | 30:8f092276b2ba | 6 | namespace SWITCH { |
M_souta | 30:8f092276b2ba | 7 | DigitalIn dipSw[] = { |
M_souta | 30:8f092276b2ba | 8 | DigitalIn(DIP0_PIN), |
M_souta | 30:8f092276b2ba | 9 | DigitalIn(DIP1_PIN), |
M_souta | 30:8f092276b2ba | 10 | DigitalIn(DIP2_PIN), |
M_souta | 30:8f092276b2ba | 11 | DigitalIn(DIP3_PIN), |
M_souta | 30:8f092276b2ba | 12 | }; |
M_souta | 30:8f092276b2ba | 13 | |
M_souta | 30:8f092276b2ba | 14 | DigitalIn digitalIn[INPUT_NUM] = { |
M_souta | 30:8f092276b2ba | 15 | DigitalIn(INPUT0_PIN), |
M_souta | 30:8f092276b2ba | 16 | DigitalIn(INPUT1_PIN), |
M_souta | 30:8f092276b2ba | 17 | DigitalIn(INPUT2_PIN), |
M_souta | 30:8f092276b2ba | 18 | DigitalIn(INPUT3_PIN), |
M_souta | 30:8f092276b2ba | 19 | DigitalIn(INPUT4_PIN), |
M_souta | 30:8f092276b2ba | 20 | DigitalIn(INPUT5_PIN), |
M_souta | 30:8f092276b2ba | 21 | DigitalIn(INPUT6_PIN), |
M_souta | 30:8f092276b2ba | 22 | DigitalIn(INPUT7_PIN), |
M_souta | 30:8f092276b2ba | 23 | DigitalIn(INPUT8_PIN), |
M_souta | 30:8f092276b2ba | 24 | DigitalIn(INPUT9_PIN), |
M_souta | 30:8f092276b2ba | 25 | DigitalIn(INPUT10_PIN), |
M_souta | 30:8f092276b2ba | 26 | DigitalIn(INPUT11_PIN), |
M_souta | 30:8f092276b2ba | 27 | DigitalIn(INPUT12_PIN), |
M_souta | 30:8f092276b2ba | 28 | DigitalIn(INPUT13_PIN), |
M_souta | 30:8f092276b2ba | 29 | DigitalIn(INPUT14_PIN), |
M_souta | 30:8f092276b2ba | 30 | DigitalIn(INPUT15_PIN), |
M_souta | 30:8f092276b2ba | 31 | DigitalIn(INPUT16_PIN), |
M_souta | 30:8f092276b2ba | 32 | DigitalIn(INPUT17_PIN), |
M_souta | 30:8f092276b2ba | 33 | DigitalIn(INPUT18_PIN), |
M_souta | 30:8f092276b2ba | 34 | DigitalIn(INPUT19_PIN), |
M_souta | 30:8f092276b2ba | 35 | }; |
M_souta | 30:8f092276b2ba | 36 | |
M_souta | 30:8f092276b2ba | 37 | void DipSw::Initialize() { |
M_souta | 30:8f092276b2ba | 38 | for(uint8_t i=0; i < sizeof(dipSw)/sizeof(dipSw[0]); i++) { |
M_souta | 30:8f092276b2ba | 39 | dipSw[i].mode(PullUp); |
M_souta | 30:8f092276b2ba | 40 | } |
M_souta | 30:8f092276b2ba | 41 | } |
M_souta | 30:8f092276b2ba | 42 | |
M_souta | 30:8f092276b2ba | 43 | uint8_t DipSw::GetStatus() { |
M_souta | 30:8f092276b2ba | 44 | if(DIP0 == SW_ON) return 0; |
M_souta | 30:8f092276b2ba | 45 | else if(DIP1 == SW_ON) return 1; |
M_souta | 30:8f092276b2ba | 46 | else if(DIP2 == SW_ON) return 2; |
M_souta | 30:8f092276b2ba | 47 | else if(DIP3 == SW_ON) return 3; |
M_souta | 30:8f092276b2ba | 48 | |
M_souta | 30:8f092276b2ba | 49 | return 0; |
M_souta | 30:8f092276b2ba | 50 | } |
M_souta | 30:8f092276b2ba | 51 | |
M_souta | 30:8f092276b2ba | 52 | void LimitSw::Initialize() { |
M_souta | 30:8f092276b2ba | 53 | for(uint8_t i = 0; i < INPUT_NUM; i++) { |
M_souta | 30:8f092276b2ba | 54 | digitalIn[i].mode(PullUp); |
M_souta | 30:8f092276b2ba | 55 | } |
M_souta | 30:8f092276b2ba | 56 | } |
M_souta | 30:8f092276b2ba | 57 | |
M_souta | 30:8f092276b2ba | 58 | bool LimitSw::IsPressed(uint8_t index) { |
M_souta | 30:8f092276b2ba | 59 | return digitalIn[index] ? false : true; |
M_souta | 30:8f092276b2ba | 60 | } |
M_souta | 30:8f092276b2ba | 61 | } |