 	Serial.print(stringBuffer);
 }
 
+void playCoinSound() {
+	int coinNotes[] = { 988, 1319 };
+	int coinNoteDurations[] = { 125, 400 };
+	int numCoinNotes = sizeof(coinNotes) / sizeof(coinNotes[0]);
+
+	for (int i = 0; i < numCoinNotes; i++) {
+        tone(speakerPin, coinNotes[i]);
+        delay(coinNoteDurations[i]);
+        noTone(speakerPin);
+    }
+}
+
 void redBeat(uint8_t wait) {
 	int i = 0;
 


SoftwareSerial RFID(RFID_RX, RFID_TX);
SoftwareSerial WIFI(WIFI_RX, WIFI_TX);

int coinNotes[] = { 988, 1319 };
int coinNoteDurations[] = { 125, 400 };
int numCoinNotes = sizeof(coinNotes) / sizeof(coinNotes[0]);

int j = 0;
unsigned long lastLEDchange = 0;
// nLEDs, dataPin, clockPin
LPD8806 LED = LPD8806(4, 10, 11);

int scannedID, prevID = 0;
unsigned char readData[bufferSize];
volatile bool isValidResponse = false;
volatile char characterRead[bufferSize];

}

void loop() {
	// Scan
	if (state == 0) {
		sendCommand(CMD_GET_SNR, blockID, machineID);
		delay(waitforSerialResponse);
		isValidResponse = getResponse(readData);

		// LEDs stay off
		digitalWrite(ledPin, LOW);
		redBeat(0);

		// If a tag is detected, go to the next state
		if (isValidResponse) {
			state = 1;
		}
	}
	// Read data 
	else if (state == 1) {
		sendCommand(CMD_READ, blockID, userData);
		delay(waitforReadResponse);
		isValidResponse = getResponse(readData);

		// If data is successfully read, alert web app
		if (isValidResponse) {
			scannedID = (int)getTime(readData, numUserBytes, userOffset);

			// LEDs on
			colorWipe(LED.Color(0, 0, 127), 0);
			digitalWrite(ledPin, HIGH);
			playCoinSound();

			WIFI.listen();
			if (id != 6 && id != 12 && id != 0 && id < 100) {
				scanTest(scannedID);
			}

			RFID.listen();
			state = 2;
		}
		// If data read fails, go back to scan state
		else {
			state = 0;
		}
	}
	// Other tag operations
	else if (state == 2) {
		sendCommand(CMD_GET_SNR, blockID, machineID);
		delay(waitforSerialResponse);
		isValidResponse = getResponse(readData);

		// If tag is removed, go back to scan state
		if (!isValidResponse) {
			state = 0;
		}
	}
	else {
		state = 0;
	}
}

void serialEvent() {
