Last active
August 29, 2015 14:11
-
-
Save extrasleepy/187225991a36bfa95cd9 to your computer and use it in GitHub Desktop.
EEPROM example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <EEPROM.h> | |
int led = 12; | |
int stored; //data stored in EEPROM | |
int address = 0; //location in EEPROM | |
void setup() { | |
Serial.begin(9600); // sets up serial communication at 9600 bitss per second | |
pinMode(led, OUTPUT); | |
stored = EEPROM.read(address); // reads the data stored in address 0 and assigns to variable | |
Serial.println(stored); // Serial print the value | |
stored++; //increment value | |
if (stored > 2) { //set this number based on how many different functions you want | |
stored = 0; | |
} | |
EEPROM.write(address, stored); //write the incremented value to EEPROM for next Arduino startup | |
} | |
void loop() { //one of 3 functions runs based on stored EEPROM value | |
switch (stored){ | |
case 0: | |
fast(); | |
break; | |
case 1: | |
slow(); | |
break; | |
case 2: | |
seizure(); | |
break; | |
} | |
} | |
void fast() { | |
digitalWrite(led, !digitalRead(led)); //set light to opposite of current state | |
delay(100); | |
fast(); | |
} | |
void slow() { | |
digitalWrite(led, !digitalRead(led)); | |
delay(1000); | |
slow(); | |
} | |
void seizure() { | |
digitalWrite(led, !digitalRead(led)); | |
delay(15); | |
seizure(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment