root / arduino-1.0 / libraries / EEPROM / examples / eeprom_write / eeprom_write.ino @ 58d82c77
History | View | Annotate | Download (877 Bytes)
1 |
/* |
---|---|
2 |
* EEPROM Write |
3 |
* |
4 |
* Stores values read from analog input 0 into the EEPROM. |
5 |
* These values will stay in the EEPROM when the board is |
6 |
* turned off and may be retrieved later by another sketch. |
7 |
*/ |
8 |
|
9 |
#include <EEPROM.h> |
10 |
|
11 |
// the current address in the EEPROM (i.e. which byte |
12 |
// we're going to write to next) |
13 |
int addr = 0; |
14 |
|
15 |
void setup() |
16 |
{ |
17 |
} |
18 |
|
19 |
void loop() |
20 |
{ |
21 |
// need to divide by 4 because analog inputs range from |
22 |
// 0 to 1023 and each byte of the EEPROM can only hold a |
23 |
// value from 0 to 255. |
24 |
int val = analogRead(0) / 4; |
25 |
|
26 |
// write the value to the appropriate byte of the EEPROM. |
27 |
// these values will remain there when the board is |
28 |
// turned off. |
29 |
EEPROM.write(addr, val); |
30 |
|
31 |
// advance to the next address. there are 512 bytes in |
32 |
// the EEPROM, so go back to 0 when we hit 512. |
33 |
addr = addr + 1; |
34 |
if (addr == 512) |
35 |
addr = 0; |
36 |
|
37 |
delay(100); |
38 |
} |