MCP23008 I2C JoyPad TEST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Wire.h> | |
| #include "Adafruit_MCP23008.h" | |
| // https://github.com/adafruit/Adafruit-MCP23008-library | |
| Adafruit_MCP23008 mcp; | |
| void setup() { | |
| Serial.begin(9600); | |
| mcp.begin(7); // I2C address ***7 | |
| mcp.pinMode(0,INPUT); mcp.pullUp(0,HIGH); | |
| mcp.pinMode(1,INPUT); mcp.pullUp(1,HIGH); | |
| mcp.pinMode(2,INPUT); mcp.pullUp(2,HIGH); | |
| mcp.pinMode(3,INPUT); mcp.pullUp(3,HIGH); | |
| mcp.pinMode(4,INPUT); mcp.pullUp(4,HIGH); | |
| mcp.pinMode(5,INPUT); mcp.pullUp(5,HIGH); | |
| mcp.pinMode(6,INPUT); mcp.pullUp(6,HIGH); | |
| mcp.pinMode(7,INPUT); mcp.pullUp(7,HIGH); | |
| pinMode(13,OUTPUT); // onboard LED | |
| while(!Serial); // wait for Serial ready (Leonardo) | |
| } | |
| int U,L,D,R,A,B; | |
| int T=0; | |
| void loop() { | |
| digitalWrite(13,T); T=T?0:1; | |
| U=mcp.digitalRead(0); | |
| L=mcp.digitalRead(1); | |
| D=mcp.digitalRead(2); | |
| R=mcp.digitalRead(3); | |
| A=mcp.digitalRead(4); | |
| B=mcp.digitalRead(5); | |
| if (!U) Serial.print("U"); | |
| if (!L) Serial.print("L"); | |
| if (!D) Serial.print("D"); | |
| if (!R) Serial.print("R"); | |
| if (!A) Serial.print("A"); | |
| if (!B) Serial.print("B"); | |
| Serial.print(" "); | |
| delay(300); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment