Author Topic: PRO onboard EEPROM access  (Read 2806 times)

defragster

  • Sr. Member
  • ****
  • Posts: 467
PRO onboard EEPROM access
« on: January 16, 2015, 02:39:01 pm »
read/write of the 512 bytes EEPROM space on the PRO:

I pulled the Arduino library over to the DigiSpark folder and it seems to work.  Otherwise it was 'Not Found'.

Is this manual library copy expected - or should that library be in the Digistump distribution?  Or is there a mechanism to have the code look for the Arduino library?  Looks like the Original Spark has the same 512bytes - is there a sample?

Finding values at 255 and setting them to zero, only 99,999 cycles left.  Combined the READ sample with the selective WRITE to ZERO.  Code below uses OLED for display, Arduino sample uses Serial.

Code: [Select]
#include <DigisparkOLED.h>
#include <Wire.h>
#include <EEPROM.h>

const char P_No_Serial[] PROGMEM = "No Serial";
const char P_Zeroed[] PROGMEM = "Zeroed:";
char PszBuff[21];
#define GetPsz( x ) (strcpy_P(PszBuff, (char*)x))  // 5242  and 114 RAM

int a = 0;
int value;

void setup() {
  oled.begin();
  oled.setFont(FONT6X8);
  oled.println(millis());
}
byte bCursor = 0x20;
// the loop routine runs over and over again forever:
void loop() {
  oled.setCursor(0, 2);
  oled.println(millis());
  oled.write(10);  // write NewLine [save 30 bytes over println]
  oled.print(GetPsz(P_No_Serial)); 
  oled.write(bCursor = ~bCursor);  // Toggle 'SPACE' with some whitish char 223.
  oled.write(10);  // write NewLine [save 30 bytes over println]
  delay(1000);
  value = EEPROM.read(a);
  oled.write(10);
  oled.print(a);
  oled.write(32);
  oled.print(value);
  oled.write(10);

  if ( 255 == value ) {
    EEPROM.write(a, 0);
    oled.print(GetPsz(P_Zeroed)); 
    oled.print(a);
    oled.println( );
  }
  a = a + 1;
  if (a == 512)
    a = 0;
}

« Last Edit: January 16, 2015, 03:11:26 pm by defragster »