Merging the PS2Keyboard and ReadWrite examples to make a "notepad"?

So far, I’ve had a lot of great results with both the PS2Keyboard and ReadWrite libraries, however combining the two is proving to be more difficult than I expected. Here is my current code:

/*
  SD card read/write
 
 This example shows how to read and write data to and from an SD card file 	
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 	 
 */
 
#include <SD.h>
#include <PS2Keyboard.h>

const int DataPin = 8;
const int IRQpin =  3;

PS2Keyboard keyboard;

File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
 keyboard.begin(DataPin, IRQpin, PS2Keymap_US);
  Serial.begin(9600);
  Serial.println("'MURICAN Keyboard Test:");
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
   
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
       // Let's take the keyboard input...
        if (keyboard.available()) {
    char c = keyboard.read();
    Serial.print(c);
    // ...print it in the Serial Monitor...
    myFile.println(c);
    // ...and print it again in the file.
    // NOTE: Make sure to somehow limit the number of characters per line.
    }
    else {Serial.print("No keyboard detected."};
	// close the file:
    myFile.close();
    Serial.println("done.");
  }
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
	// nothing happens after setup
}

I’m barely scratching the surface on this project, I suspect…Any suggestions?

Any suggestions?

Yes. The code you posted does something. Tell us what that is.

You'd, apparently, rather it did something else. Tell us that that is.

  1. I would like my code to wait for keyboard input and print a line anytime something is typed, followed by an Enter keystroke.
  2. The current code won't compile. Apparently I'm missing a parenthesis, but I can't find where.
  1. The current code won't compile. Apparently I'm missing a parenthesis, but I can't find where.

More apparently, you've failed to post the EXACT error message(s).

PaulS:

  1. The current code won't compile. Apparently I'm missing a parenthesis, but I can't find where.

More apparently, you've failed to post the EXACT error message(s).

It says "expected ) before } token", in reference to the line

else {Serial.print("No keyboard detected."};

...Whoops. Fixed it by changing that line to:

else {Serial.print("No keyboard detected.");
}

...but now I seem to be having trouble with the else statement at the end of this section, it returns a "unqualified id" or something:

  else {Serial.print("No keyboard detected.");
  }
	// close the file:
    myFile.close();
    Serial.println("done.");
  }
  } else {

but now I seem to be having trouble with the else statement at the end of this section:

Well, your indenting leaves a lot to be desired. Using Tools + Auto Format just might make it possible to see what the problem is.

I suggest that you take your snippets over to http://snippets-r-us.com. Here, strange as it may seem, we really need to see all of your code and to know just what "trouble" you are having.

PaulS:
Here, strange as it may seem, we really need to see all of your code and to know just what "trouble" you are having.

No offense, but I posted all of the code in the first post.

I posted all of the code in the first post.

Yes, but:

Fixed it by changing that line

So, now you need to post again. After using Tools + Auto Format. And, include the EXACT error message.

Alright, here’s the current code:

/*
  SD card read/write
 
 This example shows how to read and write data to and from an SD card file 	
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 	 
 */
 
#include <SD.h>
#include <PS2Keyboard.h>

const int DataPin = 8;
const int IRQpin =  3;

PS2Keyboard keyboard;

File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
 keyboard.begin(DataPin, IRQpin, PS2Keymap_US);
  Serial.begin(9600);
  Serial.println("'MURICAN Keyboard Test:");
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(10, OUTPUT);
   
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
       // Let's take the keyboard input...
        if (keyboard.available()) {
    char c = keyboard.read();
    Serial.print(c);
    // ...print it in the Serial Monitor...
    myFile.println(c);
    // ...and print it again in the file.
    // NOTE: Make sure to somehow limit the number of characters per line.
    }
    else {Serial.print("No keyboard detected.");
  }
	// close the file:
    myFile.close();
    Serial.println("done.");
  }
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    	Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
	// nothing happens after setup
}

Verifying the code results in this message:
“expected unqualified-id before ‘else’”

Not familiar with Auto Format, but using it brings up the following message:
“Auto Format Canceled: Too many right curly braces.”

Sorry for being unclear, but I’ve got a bunch of other things going on at the moment.

Not familiar with Auto Format, but using it brings up the following message:
"Auto Format Canceled: Too many right curly braces."

You will have to balance the number of open and close curly braces. Since you didn't as you were typing the code, you will need to manually indent the code to figure out where you left the left curly brace out. It will probably be somewhere near where the compiler doesn't like the else statement being placed.