Добавил сообщения об ошибках, функция write теперь повторяет функцию update, put и get теперь принимают не указатели, а данные
This commit is contained in:
1 parent
52adac2b59
commit
f33566cb41
7 files changed
+60
-112
No files matched your search
@@ -6,9 +6,6 @@
|
||||
|
||||
Running this sketch is not necessary, this is
|
||||
simply highlighting certain programming methods.
|
||||
|
||||
Written by Christopher Andrews 2015
|
||||
Released under MIT licence.
|
||||
***/
|
||||
|
||||
#include <EEPROM.h>
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
the put method will use update semantics. As in a byte
|
||||
will only be written to the EEPROM if the data is actually
|
||||
different.
|
||||
|
||||
Written by Christopher Andrews 2015
|
||||
Released under MIT licence.
|
||||
***/
|
||||
|
||||
#include <EEPROM.h>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*
|
||||
* Reads the value of each byte of the EEPROM and prints it
|
||||
* to the computer.
|
||||
* This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <EEPROM.h>
|
||||
@@ -29,29 +28,11 @@ void loop() {
|
||||
Serial.print("\t");
|
||||
Serial.print(value, DEC);
|
||||
Serial.println();
|
||||
|
||||
/***
|
||||
Advance to the next address, when at the end restart at the beginning.
|
||||
|
||||
Larger AVR processors have larger EEPROM sizes, E.g:
|
||||
- Arduino Duemilanove: 512 B EEPROM storage.
|
||||
- Arduino Uno: 1 kB EEPROM storage.
|
||||
- Arduino Mega: 4 kB EEPROM storage.
|
||||
|
||||
Rather than hard-coding the length, you should use the pre-provided length function.
|
||||
This will make your code portable to all AVR processors.
|
||||
***/
|
||||
|
||||
address = address + 1;
|
||||
if (address == EEPROM.length()) {
|
||||
address = 0;
|
||||
}
|
||||
|
||||
/***
|
||||
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
|
||||
EEPROM address is also doable by a bitwise and of the length - 1.
|
||||
|
||||
++address &= EEPROM.length() - 1;
|
||||
***/
|
||||
|
||||
delay(500);
|
||||
}
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
If a value has not changed in the EEPROM, it is not overwritten
|
||||
which would reduce the life span of the EEPROM unnecessarily.
|
||||
|
||||
Released using MIT licence.
|
||||
***/
|
||||
|
||||
#include <EEPROM.h>
|
||||
@@ -26,7 +24,7 @@ void loop() {
|
||||
0 to 1023 and each byte of the EEPROM can only hold a
|
||||
value from 0 to 255.
|
||||
***/
|
||||
int val = analogRead(0) / 4;
|
||||
int val = analogRead(0) / 16;
|
||||
|
||||
/***
|
||||
Update the particular EEPROM cell.
|
||||
@@ -43,29 +41,10 @@ void loop() {
|
||||
}
|
||||
***/
|
||||
|
||||
|
||||
/***
|
||||
Advance to the next address, when at the end restart at the beginning.
|
||||
|
||||
Larger AVR processors have larger EEPROM sizes, E.g:
|
||||
- Arduino Duemilanove: 512 B EEPROM storage.
|
||||
- Arduino Uno: 1 kB EEPROM storage.
|
||||
- Arduino Mega: 4 kB EEPROM storage.
|
||||
|
||||
Rather than hard-coding the length, you should use the pre-provided length function.
|
||||
This will make your code portable to all AVR processors.
|
||||
***/
|
||||
address = address + 1;
|
||||
if (address == EEPROM.length()) {
|
||||
address = 0;
|
||||
}
|
||||
|
||||
/***
|
||||
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
|
||||
EEPROM address is also doable by a bitwise and of the length - 1.
|
||||
|
||||
++address &= EEPROM.length() - 1;
|
||||
***/
|
||||
|
||||
delay(100);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ void loop() {
|
||||
value from 0 to 255.
|
||||
***/
|
||||
|
||||
int val = analogRead(0) / 4;
|
||||
int val = analogRead(0) / 16;
|
||||
|
||||
/***
|
||||
Write the value to the appropriate byte of the EEPROM.
|
||||
@@ -32,29 +32,10 @@ void loop() {
|
||||
|
||||
EEPROM.write(addr, val);
|
||||
|
||||
/***
|
||||
Advance to the next address, when at the end restart at the beginning.
|
||||
|
||||
Larger AVR processors have larger EEPROM sizes, E.g:
|
||||
- Arduino Duemilanove: 512 B EEPROM storage.
|
||||
- Arduino Uno: 1 kB EEPROM storage.
|
||||
- Arduino Mega: 4 kB EEPROM storage.
|
||||
|
||||
Rather than hard-coding the length, you should use the pre-provided length function.
|
||||
This will make your code portable to all AVR processors.
|
||||
***/
|
||||
addr = addr + 1;
|
||||
if (addr == EEPROM.length()) {
|
||||
addr = 0;
|
||||
}
|
||||
|
||||
/***
|
||||
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
|
||||
EEPROM address is also doable by a bitwise and of the length - 1.
|
||||
|
||||
++addr &= EEPROM.length() - 1;
|
||||
***/
|
||||
|
||||
|
||||
|
||||
delay(100);
|
||||
}
|
||||
Reference in new issue
Block a user