im making a arduino controller by sending a string of 11 values and using them via python keyboard module for keypresses, the problem is all of the digital read pins are always in the high state when viewed with serial moniter or python.
the code is this
//A1 --> yaxis
//A2 --> xaxis
//3 --> x
//4 --> c
//5 --> a
//6 --> s
//7 --> d
//8 --> esc
//9 --> tab
//10 --> space
//11 --> z
int inputPins[11] = {A0, A1, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int output[11];
void setup() {
Serial.begin(9600);
for(int i = 0; i < 12; i++){
pinMode(i, INPUT);
}
}
void loop() {
output[0] = analogRead(A0);
output[1] = analogRead(A1);
for(int i = 2; i < 12; i++){
output[i] = digitalRead(output[i]);
}
for(int i = 0; i < 11; i++){
Serial.print(output[i]);
Serial.print(" ");
}
Serial.println(output[11]);
delay(100);
}
the prompt from serial moniter
How are the switches wired to the Arduino? If they are connected between the Arduino pin and Vcc (5V or 3.3V depending on which Arduino), then you need to define the input pin mode as INPUT_PULLUP, not INPUT
[Edit: See post #5 and #6. Should have said "If they are connected between the Arduino pin and Gnd (not Vcc)]
they are wired from a breadboard of switches to the arduino, at first i thought it was some interference cause by the presence of uncertain wiring but it didnt go away when a made sure everything was right
The pinMode statement is setting pins 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11 to input mode.
This only partially matches the pins that you are using as inputs, and pins 0 and 1 are used by Serial for the transmit and receive pins.
There is no need to set any pins to INPUT mode, they default to that mode when the Arduino resets.