Ciao a tutti,
ho un problema con questa libreria, MCP23S17
Uso un arduino micro i pin sono correttamente collegati e come CS uso il pin SS.
Il primo chip ha i pin A0,A1,A2 a GND, mentre il secondo ha A0 a Vcc.
In pratica sembra non leggere l’indirizzamento.
Ecco il mio sketch!
/*
Keyboard test
*/
#include <SPI.h>
#include <MCP23S17.h>
#include <Keyboard.h>
#define CLOCK_DIVIDER (2)
String Command;
int TEST = 11; // Lato P1
int SERVICE = 11;// Lato P2
int TILT = 12; // Lato P2
int UP = 1;
int DOWN = 2;
int LEFT = 3;
int RIGHT = 4;
int T1 = 5;
int T2 = 6;
int T3 = 7;
int T4 = 8;
int T5 = 9;
int T6 = 10;
int START = 15;
int COIN = 16;
MCP P_ONE(1,SS);
MCP P_TWO(2,SS);
void setup() {
SPI.begin();
SPI.setClockDivider(CLOCK_DIVIDER);
Serial.begin(9600); // Attivo porta seriale arduino a 9600baud/s
// while (!Serial) {
// ; // wait for serial port to connect. Needed for native USB
//}
Keyboard.begin(); // Inizializzo la tastiera
P_ONE.pinMode(0xFFFF); //Abilita tutti i pin come input
P_ONE.pullupMode(0xFFFF); //Attiva il pullup su tutti i pin
P_TWO.pinMode(0xFFFF); //Abilita tutti i pin come input
P_TWO.pullupMode(0xFFFF); //Attiva il pullup su tutti i pin
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
Serial.write("Inizializzazione completa!");
}
void loop() {
if (P_ONE.digitalRead(UP) == LOW) { Keyboard.write(218); } // Freccia SU
if (P_ONE.digitalRead(DOWN) == LOW) { Keyboard.write(217); } // Freccia GIU
if (P_ONE.digitalRead(LEFT) == LOW) { Keyboard.write(216); } // Freccia SX
if (P_ONE.digitalRead(RIGHT) == LOW) { Keyboard.write(215); } // Freccia DX
if (P_ONE.digitalRead(T1) == LOW) { Keyboard.write(90); } // Tasto Z
if (P_ONE.digitalRead(T2) == LOW) { Keyboard.write(88); } // Tasto X
if (P_ONE.digitalRead(T3) == LOW) { Keyboard.write(65); } // Tasto A
if (P_ONE.digitalRead(T4) == LOW) { Keyboard.write(83); } // Tasto S
if (P_ONE.digitalRead(T5) == LOW) { Keyboard.write(81); } // Tasto Q
if (P_ONE.digitalRead(T6) == LOW) { Keyboard.write(87); } // Tasto W
if (P_ONE.digitalRead(START) == LOW) { Keyboard.write(53); } // Tasto 5
if (P_ONE.digitalRead(COIN) == LOW) { Keyboard.write(49); } // Tasto 1
if (P_TWO.digitalRead(UP) == LOW) { Keyboard.write(82); } // Tasto R
if (P_TWO.digitalRead(DOWN) == LOW) { Keyboard.write(70); } // Tasto F
if (P_TWO.digitalRead(LEFT) == LOW) { Keyboard.write(68); } // Tasto D
if (P_TWO.digitalRead(RIGHT) == LOW) { Keyboard.write(71); } // Tasto G
if (P_TWO.digitalRead(T1) == LOW) { Keyboard.write(78); } // Tasto N
if (P_TWO.digitalRead(T2) == LOW) { Keyboard.write(77); } // Tasto M
if (P_TWO.digitalRead(T3) == LOW) { Keyboard.write(72); } // Tasto H
if (P_TWO.digitalRead(T4) == LOW) { Keyboard.write(74); } // Tasto J
if (P_TWO.digitalRead(T5) == LOW) { Keyboard.write(89); } // Tasto Y
if (P_TWO.digitalRead(T6) == LOW) { Keyboard.write(85); } // Tasto U
if (P_TWO.digitalRead(START) == LOW) { Keyboard.write(54); } // Tasto 6
if (P_TWO.digitalRead(COIN) == LOW) { Keyboard.write(50); } // Tasto 2
if (P_ONE.digitalRead(TEST) == LOW) { Keyboard.write(56); } // Tasto 8
if (P_TWO.digitalRead(SERVICE) == LOW) { Keyboard.write(57); } // Tasto 9
if (P_TWO.digitalRead(TILT) == LOW) { Keyboard.write(194); } // Tasto F1
delay(50);
}
Qualche consiglio?