sterretje:
There is no real difference between any read method (serial, file, ...). So I suggest that you read (possibly again) Serial Input Basics - updated; saves me a lot of typing ;). Example 2 will probably be a good option.
Ok. I read through Example 2. I didn't really understand it (Could you explain it to me? It confused me
) Anyways, I editied to the best of my ability. I basically replaced "Serial.read()" with "Keyboard.read()" so it would be reading from the keyboard, not the Serial Receive Buffer. I kept Serial.print() though. Here is my modified code:
#include <PS2Keyboard.h> //Keyboard
// Example 2 - Receive with an end-marker
const int DataPin = 18;
const int IRQpin = 19;
PS2Keyboard keyboard;
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
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) {
rc = keyboard.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
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;
}
}
When I run this code, it compiles. On the serial monitor, it says "Arduino is Ready." However, when I type something on the PS2 keyboard, nothing happens!!
Could someone please explain this to me??
I love all the help so far! ![]()