]> git.piffa.net Git - sketchbook_andrea/blob - advanced_projects/eeprom_1_write_read/eeprom_1_write_read.ino
Serial and eeprom
[sketchbook_andrea] / advanced_projects / eeprom_1_write_read / eeprom_1_write_read.ino
1 /*
2   EEPROM 
3  
4  Storaggio di un valore e sucessiva lettura.
5  */
6
7 #include <EEPROM.h>
8
9 // the current address in the EEPROM (i.e. which byte
10 // we're going to write to next)
11 int addr = 12;
12
13 void setup()
14
15   Serial.begin(9600);
16   Serial.println("Storaggio valore");
17   // EEPROM.write(addr, 124); 
18   // Eseguire una volta sola, caricare lo sketch
19   // e immediatamente commetare e ripetere l'upload.
20 }
21
22 void loop()
23 {
24   Serial.print("Lettura Valore: ");
25   Serial.println(EEPROM.read(12)); 
26   Serial.flush();
27   exit(0) ;
28   // need to divide by 4 because analog inputs range from
29   // 0 to 1023 and each byte of the EEPROM can only hold a
30   // value from 0 to 255.
31   int val = analogRead(0) / 4;
32
33   // write the value to the appropriate byte of the EEPROM.
34   // these values will remain there when the board is
35   // turned off.
36   EEPROM.write(addr, val);
37
38   // advance to the next address.  there are 512 bytes in 
39   // the EEPROM, so go back to 0 when we hit 512.
40   addr = addr + 1;
41   if (addr == 512)
42     addr = 0;
43
44   delay(100);
45 }
46