Hello everybody!
I try to build a circuit with 6 buttons which are connected to 6 digital pins. I tried to multiply this solution:
I connected every button to an own digital pin and connected it with a 10k resistor to the ground.
Here is my code:
int button1 = 2;
int button2 = 3;
int button3 = 4;
int button4 = 5;
int button5 = 6;
int button6 = 7;
int state[6];
int val[] = {
0,0,0,0,0,0};
void setup() {
Serial.begin(9600);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
pinMode(button5, INPUT);
pinMode(button6, INPUT);
}
void loop(){
state[0] = digitalRead(button1);
state[1] = digitalRead(button2);
state[2] = digitalRead(button3);
state[3] = digitalRead(button4);
state[4] = digitalRead(button5);
state[5] = digitalRead(button6);
for (int i = 0; i < 6; i++) {
if (state[i] == HIGH) {
val[i] = 1;
}
else {
val[i] = 0;
}
}
Serial.println(val[0]);
Serial.println(val[1]);
Serial.println(val[2]);
Serial.println(val[3]);
Serial.println(val[4]);
Serial.println(val[5]);
delay(100);
}
It gives my this compilingerror:
Error inside Serial.serialEvent()
java.io.IOException: Bad file descriptor in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)
at processing.app.Serial.serialEvent(Serial.java:215)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Is the code the problem or the circuit?