eeprom1.cpp

This sketch uses eepromRead and eepromWrite to read and write one byte of EEPROM. The last value written by a 'wX' packet (whatever 'X' is) will be read by subsequent 'r' packets, even after the board is rebooted or power-cycled.

// Eeprom sketch 1: Read and write a byte from the EEPROM.

// Packet 'r' reads byte from EEPROM
void doRead(u8 *) {
  u8 b;                        // Room for a byte
  eepromRead(0, &b, 1);        // Read 1 byte from address 0 of EEPROM, store in b
  logNormal("Read '%#c'\n",b); // Report results
}

// Packet 'wX' writes 'X' to EEPROM
void doWrite(u8 * packet) {
  u8 b;
  if (packetScanf(packet, "w%c",&b) != 2) // Parse packet, get byte to write
    return;
  eepromWrite(0, &b, 1);       // Write 1 byte to address 0
  logNormal("Wrote '%#c'\n", b); // Report it
}

void setup() {
  Body.reflex('r',doRead);
  Body.reflex('w',doWrite);
}

void loop() { /* Nothing to do */ }

Generated on Fri Apr 22 06:54:10 2011 for SFB by doxygen 1.5.9