Skip to content

Instantly share code, notes, and snippets.

@houmei
Created July 20, 2014 15:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
MCP23008 I2C JoyPad TEST
#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