Skip to content

Commit 0cb9e46

Browse files
committed
Example updated
1 parent ffe98c5 commit 0cb9e46

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

examples/rotaryEncoderLed23017/rotaryEncoderLed23017.ino

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,69 +31,68 @@ IOLOG_MBED_PORT_IF_NEEDED(USBTX, USBRX);
3131
//const int ledB = 9;
3232
//const int attachedInterruptPin = 2;
3333

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;
4040

4141

4242
// Arduino 23017 interrupt pin connection, and reset pin connection
4343
const int resetPin23017 = 32;
4444

45-
IoAbstractionRef io23017;
45+
MCP23017IoAbstraction mcp23017(0x20, ACTIVE_LOW_OPEN, attachedInterruptPin, IO_PIN_NOT_DEFINED);
4646

4747
//
4848
// this function is called by switches whenever the button is pressed.
4949
//
5050
void onKeyPressed(pinid_t key, bool held) {
5151
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);
5454
}
5555

5656
void onKeyReleased(pinid_t key, bool held) {
5757
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);
6060
}
6161

6262
void onEncoderChange(int encoderValue) {
6363
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);
6666
}
6767

6868
void setup() {
6969
IOLOG_START_SERIAL
70-
Wire.begin(4, 15);
70+
Wire.begin();
71+
//Wire.begin(4, 15);
7172

7273
// this is optional, in a real world system you could probably just connect the
7374
// reset pin of the device to Vcc, but when prototyping you'll want a reset
7475
// 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);
7878
taskManager.yieldForMicros(100);
79-
ioDeviceDigitalWriteS(deviceIo, resetPin23017, HIGH);
80-
81-
io23017 = ioFrom23017(0x20, ACTIVE_LOW_OPEN, attachedInterruptPin);
79+
internalDigitalDevice().digitalWriteS(resetPin23017, HIGH);
8280

8381
serdebugF("Starting LED example on 23017 example");
8482

85-
ioDevicePinMode(io23017, ledA, OUTPUT);
86-
ioDevicePinMode(io23017, ledB, OUTPUT);
83+
mcp23017.pinMode(ledA, OUTPUT);
84+
mcp23017.pinMode(ledB, OUTPUT);
8785

8886
// 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);
9088

9189
// we now add both a press and release and handler.
9290
switches.addSwitch(encoderOK, onKeyPressed, 20);
9391
switches.onRelease(encoderOK, onKeyReleased);
9492

9593
// and set up an encoder on the same device.
9694
setupRotaryEncoderWithInterrupt(encoderA, encoderB, onEncoderChange);
95+
switches.changeEncoderPrecision(0, 0);
9796
}
9897

9998
void loop() {

0 commit comments

Comments
 (0)