Thanks in advance. And sorry if this is posted in the wrong place...
I'm a complete novice at this having only been playing around with Arduino for the last few days, and I'm no programmer either.
However I've managed to make a working keypad using the Arduino Leonardo (chosen for its USB functionality) and some DIY switches etc. This is just a basic test to see whether I could achieve what I want - ultimately I want to make a USB keypad footswitch using more robust materials.
here's a video of what I've made (it's basic):
My method, including the sketch info is all on my website here:
http://www.mrjones.education/arduino-usb-number-pad-project/
My question is: Is my setup OK - it works but I don't want to damage PC or the Arduino because it isn't properly wired?
Also - could the sketch be improved?
Thanks again
I am unable to access the links at this time so will make general comment.
If you project uses the USB for power and there are no other voltages applied, you cannot damage the PC.
If your wiring is done properly and carefully, there should be no problems.
Weedpharma
http://www.mrjones.education/arduino-usb-number-pad-project/
The wiring looks fine and should cause no harm to the PC.
case '#':
Keyboard.write(000011012);
break;
That's a weird value. Does '#' not work?
000011012 is an OCTAL constant (because it has a leading 0). It translates to 0x00120A or decimal 4618. Since Keyboard.press() only takes a byte the low-order 8 bits (0x0A) are used and that is the linefeed/newline/Enter character.
If linefeed was the intent, I'd use Keyboard.write(0x0A);
switch (key)
{
case '1':
Keyboard.write('1');
break;
case '2':
Keyboard.write('2');
break;
case '3':
Keyboard.write('3');
break;
case '4':
Keyboard.write('4');
break;
case '5':
Keyboard.write('5');
break;
case '6':
Keyboard.write('6');
break;
case '7':
Keyboard.write('7');
break;
case '8':
Keyboard.write('8');
break;
case '9':
Keyboard.write('9');
break;
case '0':
Keyboard.write('0');
break;
case '*':
Keyboard.write('*');
break;
case '#':
Keyboard.write(000011012);
break;
}
You can simplify this to:
if (key == '#')
Keyboard.write(0x0A);
else
Keyboard.write(key);
Sorry... the link to the page isn't working right now... typical that server is down right when I direct people to it.
Good to know all wiring is okay...
The # key I'm using as an enter key so I entered the binary code for 'enter / carriage return' - 000011012 (which works).
Thanks for this, feeling more confident now.
mrjonesed:
The # key I'm using as an enter key so I entered the binary code for 'enter / carriage return' - 000011012 (which works).
You may have thought you were entering binary but 2 is not a binary digit and there is no prefix to say it is binary (most compilers accept 0b00001101 and Arduino defines B00001101). It's a string of octal digits starting with a 0 so it will be treated as an octal constant.
You are lucky that in Octal "000011012" ends in 0b00001010 which is the character code for Newline/Linefeed. What you intended was 0b00001101 which is 0x0D, the character code for Return.
Thanks - you're right, I copied it from somewhere online and it worked so didn't question it...
Thanks for taking the time to comment - I shall amend it so at least its 'proper'.
Thanks again