Hi
I am trying to create a keyboard with arduino Due /Leonardo and i can not get a stable input on both boards ' its like some keys are repeating themselves .
I have switched to arduino Mega
Changed the "keyboard.write" to "Serial.write" and the inputs are stable on the arduino Mega.
I did not change the electric wiring between the different boards , so its definitely something with the boards themself .
Any one had this problem ?
attached wiring diagram
/*
*/
#include "Keyboard.h"
// the setup routine runs once when you press reset:
void setup() {
pinMode(30, INPUT); // set pin to input
pinMode(31, INPUT); // set pin to input
pinMode(32, INPUT); // set pin to input
pinMode(33, INPUT); // set pin to input
pinMode(34, INPUT); // set pin to input
pinMode(35, INPUT); // set pin to input
pinMode(36, INPUT); // set pin to input
pinMode(37, INPUT); // set pin to input
pinMode(38, INPUT); // set pin to input
pinMode(39, INPUT); // set pin to input
pinMode(40, INPUT); // set pin to input
pinMode(41, INPUT); // set pin to input
pinMode(42, INPUT); // set pin to input
pinMode(43, INPUT); // set pin to input
pinMode(44, INPUT); // set pin to input
pinMode(45, INPUT); // set pin to input
//pinMode(46, INPUT); // set pin to input
/*
*
*
*
*/
// initialize serial communication at 9600 bits per second:
// Keyboard.begin();
Serial.begin(115200);
}
// the loop routine runs over and over again forever:
void loop() {
if(digitalRead(30)==HIGH){
Serial.write(65); //A
}
if(digitalRead(31)==HIGH){
Serial.write(66); //B
}
if(digitalRead(32)==HIGH){
Serial.write(67); //C
}
if(digitalRead(33)==HIGH){
Serial.write(68); //D
}
if(digitalRead(34)==HIGH){
Serial.write(69); //E
}
if(digitalRead(35)==HIGH){
Serial.write(70); //F
}
if(digitalRead(36)==HIGH){
Serial.write(71); //G
}
if(digitalRead(37)==HIGH){
Serial.write(72); //H
}
if(digitalRead(38)==HIGH){
Serial.write(73); //I
}
if(digitalRead(39)==HIGH){
Serial.write(74); //J
}
if(digitalRead(40)==HIGH){
Serial.write(75); //K
}
if(digitalRead(41)==HIGH){
Serial.write(76); //L
}
if(digitalRead(42)==HIGH){
Serial.write(77); //M
}
if(digitalRead(43)==HIGH){
Serial.write(78); // N
}
if(digitalRead(44)==HIGH){
Serial.write(79); //O
}
if(digitalRead(45)==HIGH){
Serial.write(80); //P
}
delay(100); // delay in between reads for stability
}
I'm quite sure the provided sketch won't work with the provided wiring, not on a Mega and never on a Leonardo. The circuit is simply wrong.
You might move the resistor to replace the left red line and connect the LED output directly to GND. But then you have to check for a LOW state of the input as the default will be HIGH. And you should debounce it, as physical button almost always bounce (go on and off a few times very fast if pushed).
Sorry didnt notice i connected the input in the schematic wrong , posted update schematic , the LED is for 2 reasons , make sure the key works and prevent backflow to the input from the ground
Sadly that is what i started with , an i get the same result , i switch to this set up because i figured that there might be some resistance on the ground and then i get some current flowing back to the input pins .
what i am trying to figure out is why is this or the set up you suggested worjing on the Mega and not working on Leonardo nor Due
(i try again the your set up and post back )
A LED/resistor is like a zener diode, and can't be used to properly pull a switch pin up (or down).
If you use internal pull up one the pin, as I explained, it should work for both 3.3volt (Due) and 5volt Arduinos.
Post a real picture and the code if you're still having problems.
Leo..