im trying to cut and paste my way through life.
here is my code:
#include <Time.h>
#include <Keypad.h>
#include <SD.h>
#include <MagStripe.h> //magcardstripe lib
/* Power consumption
Card Reader - 5 mA
SD Card - 75 mA (3.3V ONLY!)
LED - 20 mA/Color. 60 mA total
/*============================================
PIN MAP
==============================================
9 - Chip Select for Card Reader
10 - Chip Select for SD Card
11 - DOUT for SPI Devices (Connects to MOSI of device)
12 - DIN for SPI Devices (Connect to MISO of device)
13 - CLK for SPI Devices
14 - \
15 - \
16 - \
17 - | Pins for Key Pad
18 - /
19 - /
20 - /
21 - LED Indicator - Red
22 - LED Indicator - Green
23 - LED Indicator - Blue
*/
static int DEV_MAGCARD = 9;
static int DEV_SDCARD = 10;
/*============================================
SD Card Reader
============================================== */
File curFile;
String curCsv;
char cFilename[8];
/*============================================
Key Pad Definitions
============================================== */
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[rows] = {14, 15, 16, 17}; //connect to the row pinouts of the keypad
byte colPins[cols] = {18, 19, 20}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
char keyPadEntry[9];
int keyPadCurPlace = 0;
/*============================================
LED Status Indicator
============================================== */
const int rLedPin = 21;
const int gLedPin = 22;
const int bLedPin = 23;
const int LED_GREEN = 1;
const int LED_RED = 2;
const int LED_YELLOW = 3;
const int LED_WHITE = 4;
const int LED_BLUE = 5;
const int LED_PURPLE = 6;
/*============================================
Mag Card Reader
============================================== */
MagStripe card;
static const byte DATA_BUFFER_LEN = 108;
static char data[DATA_BUFFER_LEN];
void setup() {
//Set up Status LED and turn it red while booting up
pinMode(gLedPin, OUTPUT);
pinMode(rLedPin, OUTPUT);
pinMode(bLedPin, OUTPUT);
statusLED(LED_YELLOW);
setTime(1369811858);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}
//Set up the SD Card
Serial.print("Initializing SD card...");
pinMode(DEV_SDCARD, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(DEV_SDCARD)) {
Serial.println("Card failed, or not present");
statusLED(LED_RED);
// don't do anything more:
return;
}
Serial.println("card initialized.");
//Check to see if there is a file for today's date already
curCsv = String(year()).concat(getMonth()).concat(getDay()).concat(String(".csv"));
Serial.println(curCsv);
curCsv.toCharArray(cFilename, sizeof(cFilename));
//If the file doesn't exist, then create it.
if (!SD.exists(cFilename)) {
curFile = SD.open(cFilename, FILE_WRITE);
curFile.close();
Serial.println("Today's File was Created");
} else {
Serial.println("Today's File Exists");
}
//Setup MagCard reader
card.begin(2);
statusLED(LED_GREEN);
}
void loop() {
// Don't do anything if there isn't a card present...
if (card.available()) {
// Read the card into the buffer "data" (as a null-terminated string)...
short chars = card.read(data, DATA_BUFFER_LEN);
// If there was an error reading the card, blink the error LED...
if (chars < 0) {
Serial.println("Error. Card not read.");
return;
} else {
writeSwipe(data);
Serial.println(data);
}
}
char key = keypad.getKey();
if(key) // Check for a valid key.
{
switch (key)
{
case '*':
spiSelect(DEV_SDCARD);
curFile = SD.open(cFilename, FILE_READ);
while(curFile.available()) {
Serial.write(curFile.read());
}
curFile.close();
spiSelect(DEV_MAGCARD);
break;
case '#':
spiSelect(DEV_SDCARD);
SD.remove(cFilename);
spiSelect(DEV_MAGCARD);
break;
default:
keyPadEntry[keyPadCurPlace] = key;
if (keyPadCurPlace == 8) {
keyPadEntry[keyPadCurPlace + 1] = '\0';
Serial.println(keyPadEntry);
writeSwipe(keyPadEntry);
keyPadCurPlace = 0;
} else {
keyPadCurPlace++;
}
}
}
}
void statusLED(int sLedColor) {
switch (sLedColor) {
case LED_GREEN:
analogWrite(gLedPin, 0);
analogWrite(rLedPin, 255);
analogWrite(bLedPin, 255);
break;
case LED_RED:
analogWrite(gLedPin, 255);
analogWrite(rLedPin, 0);
analogWrite(bLedPin, 255);
break;
case LED_YELLOW:
analogWrite(gLedPin, 0);
analogWrite(rLedPin, 0);
analogWrite(bLedPin, 255);
break;
case LED_WHITE:
analogWrite(gLedPin, 0);
analogWrite(rLedPin, 0);
analogWrite(bLedPin, 0);
break;
case LED_BLUE:
analogWrite(gLedPin, 255);
analogWrite(rLedPin, 255);
analogWrite(bLedPin, 0);
break;
case LED_PURPLE:
analogWrite(gLedPin, 255);
analogWrite(rLedPin, 128);
analogWrite(bLedPin, 128);
break;
default:
break;
}
}
int writeSwipe(String stuID) {
//Let the SD Card Control
spiSelect(DEV_SDCARD);
curFile = SD.open(cFilename, FILE_WRITE);
curFile.println(stuID.concat(",").concat(String(now())));
curFile.close();
//Return control back to the Mag card reader
spiSelect(DEV_MAGCARD);
}
String getMonth() {
String tmpString = month();
if (tmpString.length() < 2) {
String tmpStringN = String('0').concat(tmpString);
return tmpStringN;
}
else {
return tmpString;
}
}
String getDay() {
String tmpString = day();
if (tmpString.length() < 2) {
String tmpStringN = String('0').concat(tmpString);
return tmpStringN;
}
else {
return tmpString;
}
}
void spiSelect(int spiDev) {
if (spiDev == DEV_SDCARD) {
digitalWrite(DEV_SDCARD, LOW);
} else {
digitalWrite(DEV_SDCARD, HIGH);
}
if (spiDev == DEV_MAGCARD) {
digitalWrite(DEV_MAGCARD, LOW);
} else {
digitalWrite(DEV_MAGCARD, HIGH);
}
}
and this is the errors im getting:
sketch_sep16a.ino: In function 'void setup()':
sketch_sep16a:112: error: request for member 'concat' in 'String(year(), 10u).String::concat(((const String&)((const String*)(& getMonth()()))))', which is of non-class type 'unsigned char'
sketch_sep16a.ino: In function 'int writeSwipe(String)':
sketch_sep16a:249: error: request for member 'concat' in 'stuID.String::concat(((const char*)","))', which is of non-class type 'unsigned char'
sketch_sep16a.ino: In function 'String getMonth()':
sketch_sep16a:258: error: invalid conversion from 'int' to 'const char*'
sketch_sep16a:258: error: initializing argument 1 of 'String::String(const char*)'
sketch_sep16a:260: error: invalid conversion from 'unsigned char' to 'const char*'
sketch_sep16a:260: error: initializing argument 1 of 'String::String(const char*)'
sketch_sep16a.ino: In function 'String getDay()':
sketch_sep16a:269: error: invalid conversion from 'int' to 'const char*'
sketch_sep16a:269: error: initializing argument 1 of 'String::String(const char*)'
sketch_sep16a:271: error: invalid conversion from 'unsigned char' to 'const char*'
sketch_sep16a:271: error: initializing argument 1 of 'String::String(const char*)'
do i need to edit the lib or this code? any tips are appreciated