// This project discards the Serial output from the sketch;
// instead, it connects the serial monitor to a physical serial port on your computer.
//
// Only works on Chrome
#include <EEPROM.h>
const int eepromSize = 1024; // EEPROM size in bytes (for Arduino Uno)
const int dataSize = 1000; // Expected data size
int writeIndex = 0; // Track the number of bytes received
int readIndex = 0; // Track the number of bytes read from EEPROM
bool dataReceived = false;
void setup() {
Serial.begin(2400); // Set baud rate to 2400
Serial.write("hello");
}
void loop() {
// Receiving data byte-by-byte and storing in EEPROM
while (Serial.available() > 0 && !dataReceived) {
char incomingByte = Serial.read();
// Store each received byte in EEPROM if there's space
if (writeIndex < eepromSize) {
EEPROM.write(writeIndex++, incomingByte);
}
// Check if 1000 bytes have been received
if (writeIndex >= dataSize) {
dataReceived = true;
}
}
// If all data has been received, send it back to the PC
if (dataReceived) {
// Loop through EEPROM and send stored data byte-by-byte to the PC
while (readIndex < writeIndex) {
char outByte = EEPROM.read(readIndex++);
Serial.write(outByte);
delay(10); // Optional: Delay to ensure smooth transmission at 2400 baud
}
// Reset indexes and flag after transmission is complete
writeIndex = 0;
readIndex = 0;
dataReceived = false;
}
}