Skip to content

Commit

Permalink
Update mcp23s18_SPI_basic_input_output.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
wollewald authored Oct 28, 2022
1 parent 1ad8949 commit f8f6435
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ https://wolles-elektronikkiste.de/en/port-expander-mcp23017-2
/* There are two ways to create your MCP23S18 object:
* MCP23S18 myMCP = MCP23S18(CS_PIN, RESET_PIN, MCP_CTRL_BYTE);
* MCP23S18 myMCP = MCP23S18(&SPI, CS_PIN, RESET_PIN, MCP_CTRL_BYTE);
* The second option allows you to create your own SPI objects,
* e.g. in order to use two SPI interfaces on the ESP32.
* The second option allows you to pass SPI objects, e.g. in order to
* use two SPI interfaces on the ESP32.
*/

MCP23S18 myMCP = MCP23S18(CS_PIN, RESET_PIN, MCP_SPI_CTRL_BYTE);
Expand All @@ -45,8 +45,8 @@ void setup(){
}
// myMCP.setSPIClockSpeed(8000000); // Choose SPI clock speed (after Init()!)
delay(wT);
myMCP.setAllPins(A,OFF); // Port A: all pins are LOW (OFF = LOW = 0)
myMCP.setAllPins(B,OFF); // Port B: all pins are LOW
myMCP.setAllPins(A, LOW); // Port A: all pins are LOW (OFF = LOW = 0)
myMCP.setAllPins(B, LOW); // Port B: all pins are LOW
myMCP.setPortMode(0b11111111, A); // Port A: all pins are OUTPUT = LEDs are on!
myMCP.setPortMode(0b11111111, B); // Port B: all pins are OUTPUT
delay(wT);
Expand All @@ -65,25 +65,25 @@ void setup(){
myMCP.setPortMode(portModeValue, B);
delay(wT);
}
myMCP.setPortMode(0,A); // Port A: all pins are INPUT
myMCP.setPortMode(0,B); // Port B: all pins are INPUT
myMCP.setPortMode(0, A); // Port A: all pins are INPUT
myMCP.setPortMode(0, B); // Port B: all pins are INPUT
delay(wT);
myMCP.setPinMode(3, A, OUTPUT); // Pin 3 / PORT A is OUTPUT/LOW
myMCP.setPinMode(1, B, OUTPUT); // Pin 1 / PORT B is OUTPUT/LOW
delay(wT);
myMCP.setPortMode(0,A); // Port A: all pins are INPUT
myMCP.setPortMode(0,B); // Port B: all pins are INPUT
myMCP.setPinX(1,A,OUTPUT,LOW); // A1 HIGH
myMCP.setPortMode(0, A); // Port A: all pins are INPUT
myMCP.setPortMode(0, B); // Port B: all pins are INPUT
myMCP.setPinX(1, A, OUTPUT, LOW); // A1 HIGH
delay(wT);
myMCP.togglePin(1, A); // A1 LOW
delay(wT);
myMCP.togglePin(1, A); // A1 HIGH
delay(wT);
// the following two lines are similar to setPinX(2,B,OUTPUT,LOW);
myMCP.setPinMode(2,B,OUTPUT); // B2 is OUTPUT/LOW
myMCP.setPin(2,B,LOW); // B2 is still OUTPUT/LOW
myMCP.setPinMode(2, B, OUTPUT); // B2 is OUTPUT/LOW
myMCP.setPin(2, B, LOW); // B2 is still OUTPUT/LOW
delay(wT);
myMCP.setPortX(0b10001111,0b10000000,B); // B0-B4: OUTPUT/LOW, B7: OUTPUT, HIGH;
myMCP.setPortX(0b10001111, 0b10000000, B); // B0-B4: OUTPUT/LOW, B7: OUTPUT, HIGH;
}

void loop(){
Expand Down

0 comments on commit f8f6435

Please sign in to comment.