@@ -31,69 +31,68 @@ IOLOG_MBED_PORT_IF_NEEDED(USBTX, USBRX);
31
31
// const int ledB = 9;
32
32
// const int attachedInterruptPin = 2;
33
33
34
- const int encoderA = 12 ;
35
- const int encoderB = 14 ;
36
- const int encoderOK = 13 ;
37
- const int ledA = 6 ;
38
- const int ledB = 7 ;
39
- const int attachedInterruptPin = 26 ;
34
+ const int encoderA = 6 ;
35
+ const int encoderB = 7 ;
36
+ const int encoderOK = 5 ;
37
+ const int ledA = 4 ;
38
+ const int ledB = 3 ;
39
+ const int attachedInterruptPin = 2 ;
40
40
41
41
42
42
// Arduino 23017 interrupt pin connection, and reset pin connection
43
43
const int resetPin23017 = 32 ;
44
44
45
- IoAbstractionRef io23017 ;
45
+ MCP23017IoAbstraction mcp23017 ( 0x20 , ACTIVE_LOW_OPEN, attachedInterruptPin, IO_PIN_NOT_DEFINED) ;
46
46
47
47
//
48
48
// this function is called by switches whenever the button is pressed.
49
49
//
50
50
void onKeyPressed (pinid_t key, bool held) {
51
51
serdebugF3 (" key pressed" , key, held);
52
- ioDeviceDigitalWrite (io23017, ledA, HIGH);
53
- ioDeviceDigitalWriteS (io23017, ledB, HIGH);
52
+ mcp23017. digitalWrite ( ledA, HIGH);
53
+ mcp23017. digitalWriteS ( ledB, HIGH);
54
54
}
55
55
56
56
void onKeyReleased (pinid_t key, bool held) {
57
57
serdebugF3 (" key released" , key, held);
58
- ioDeviceDigitalWrite (io23017, ledA, LOW);
59
- ioDeviceDigitalWriteS (io23017, ledB, LOW);
58
+ mcp23017. digitalWrite ( ledA, LOW);
59
+ mcp23017. digitalWriteS ( ledB, LOW);
60
60
}
61
61
62
62
void onEncoderChange (int encoderValue) {
63
63
serdebugF2 (" encoder = " , encoderValue);
64
- ioDeviceDigitalWrite (io23017, ledA, encoderValue < 0 );
65
- ioDeviceDigitalWriteS (io23017, ledB, encoderValue > 0 );
64
+ mcp23017. digitalWrite ( ledA, encoderValue < 0 );
65
+ mcp23017. digitalWriteS ( ledB, encoderValue > 0 );
66
66
}
67
67
68
68
void setup () {
69
69
IOLOG_START_SERIAL
70
- Wire.begin (4 , 15 );
70
+ Wire.begin ();
71
+ // Wire.begin(4, 15);
71
72
72
73
// this is optional, in a real world system you could probably just connect the
73
74
// reset pin of the device to Vcc, but when prototyping you'll want a reset
74
75
// on every restart.
75
- auto * deviceIo = internalDigitalIo ();
76
- ioDevicePinMode (deviceIo, resetPin23017, OUTPUT);
77
- ioDeviceDigitalWriteS (deviceIo, resetPin23017, LOW);
76
+ internalDigitalDevice ().pinMode (resetPin23017, OUTPUT);
77
+ internalDigitalDevice ().digitalWriteS (resetPin23017, LOW);
78
78
taskManager.yieldForMicros (100 );
79
- ioDeviceDigitalWriteS (deviceIo, resetPin23017, HIGH);
80
-
81
- io23017 = ioFrom23017 (0x20 , ACTIVE_LOW_OPEN, attachedInterruptPin);
79
+ internalDigitalDevice ().digitalWriteS (resetPin23017, HIGH);
82
80
83
81
serdebugF (" Starting LED example on 23017 example" );
84
82
85
- ioDevicePinMode (io23017, ledA, OUTPUT);
86
- ioDevicePinMode (io23017, ledB, OUTPUT);
83
+ mcp23017. pinMode ( ledA, OUTPUT);
84
+ mcp23017. pinMode ( ledB, OUTPUT);
87
85
88
86
// here we initialise switches in interrupt mode, using pull up logic by default.
89
- switches.init (io23017 , SWITCHES_NO_POLLING, true );
87
+ switches.init (asIoRef (mcp23017) , SWITCHES_NO_POLLING, true );
90
88
91
89
// we now add both a press and release and handler.
92
90
switches.addSwitch (encoderOK, onKeyPressed, 20 );
93
91
switches.onRelease (encoderOK, onKeyReleased);
94
92
95
93
// and set up an encoder on the same device.
96
94
setupRotaryEncoderWithInterrupt (encoderA, encoderB, onEncoderChange);
95
+ switches.changeEncoderPrecision (0 , 0 );
97
96
}
98
97
99
98
void loop () {
0 commit comments