Devices & Components
Arduino Mega 2560 Rev3
Project description
Code
Code EEPROM
arduino
1#include <EEPROM.h> 2 3void setup() { 4 pinMode(10, INPUT_PULLUP); //because of the pullup resistor we dont need an external resistor 5 pinMode(LED_BUILTIN, OUTPUT); 6} 7 8 9 10void loop() { 11 bool button_pressed = digitalRead(10); 12 13 if(!button_pressed && EEPROM.read(0) == 0){ 14 EEPROM.write(0, 1); //EEPROM.write(address, value) ; the value should be between 0 and 255 15 } 16 17 else if(!button_pressed){ 18 EEPROM.update(0, 0); //the update function writes only to the EEPROM if the new value 19 //is not the same as the old one. In some cases this is very important 20 //to save cylces on the EEPROM. 21 } 22 23 delay(100); 24 digitalWrite(LED_BUILTIN, EEPROM.read(0)); 25}
Downloadable files
Schematics
Schematics

Schematics
Schematics

Comments
Only logged in users can leave comments