sterretje:
When the '\n' is received, a flag is set to indicate that the message is complete and sets 'ndx' to 0 for the next
For a 'a', you should see 61, for a 'b' 62 and so on. For a '0' you should see '30', for '1' you should see '31' etc. See asciitable.com
Great! I will try to get the library for you... It was so long ago I can't remember where I got it.
Hardware:
-
Arduino MEGA
-
Ps2 Adapter: https://www.amazon.com/gp/product/B00XRRNV4A/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
-
Keyboard: https://www.amazon.com/gp/product/B0075W8C8S/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1
Ok. So I ran this code:
// Example 2 - Receive with an end-marker
#include <PS2Keyboard.h> //Keyboard
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
const int DataPin = 18;
const int IRQpin = 19;
boolean newData = false;
PS2Keyboard keyboard;
void setup() {
Serial.begin(9600);
keyboard.begin(DataPin, IRQpin);
Serial.println("<Arduino is ready>");
}
void loop() {
recvWithEndMarker();
showNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (keyboard.available() > 0 && newData == false)
{
Serial.println("characters available");
rc = keyboard.read();
Serial.print(rc, HEX);
if (rc != endMarker)
{
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else
{
Serial.println(" endMarker received");
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
On the serial monitor, I got this:
<Arduino is ready>
characters available
63characters available
67characters available
61characters available
64characters available
64characters available
65characters available
61characters available
65characters available
72characters available
61 was infact the letter A!
The letter B was 62!
When I hit ENTER on the keyboard, it prints the letter "D"
Where should I go from here? With this current code, are all the values being stored into the buffer? Can I just print the buffer and have all the numbers displayed on the same line, in the same thing?
Thanks SO much for the help so far!