-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheeprom_bits.ino
55 lines (36 loc) · 1.19 KB
/
eeprom_bits.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/***
eeprom_bits example.
This example sketch is highlighting the usage
of EEPROM.readBit() and EEPROM.writeBit().
Written by Christopher Andrews 2015
Released under MIT licence.
***/
#include <EEPROM.h>
void setup() {
int address = 0; //Address to first EEPROM cell.
EEPROM.start();
delay( 2000 ); //Prevent touching the EEPROM through resets and uploading of sketch.
SerialUSB.begin( 9600 );
while (!SerialUSB) {
; // wait for serial port to connect. Needed for Leonardo boards only.
}
//Clear first cell so we can see the changes.
EEPROM.update( address, 0 );
SerialUSB.print( "Contents of cell 0: " );
SerialUSB.println( EEPROM.read( address ), HEX );
delay( 500 );
//Set the fourth bit HIGH, or true
EEPROM.writeBit( address, 3, true ); //Parameters: cell index, bit index, value
SerialUSB.print( "Contents of cell 0 after setting bit: " );
SerialUSB.println( EEPROM.read( address ), HEX );
delay( 500 );
SerialUSB.print( "Value of fourth bit: " );
bool value = EEPROM.readBit( address, 3 );
if( value ){
SerialUSB.println( "true" );
}else{
SerialUSB.println( "false" );
}
}
void loop(){
}