if i had 9 boolean and 8 unsigned longs is it safe to assume i can start EEPROM in esp8266 with only 41 bytes?
EEPROM.begin(41);
if i had 9 boolean and 8 unsigned longs is it safe to assume i can start EEPROM in esp8266 with only 41 bytes?
EEPROM.begin(41);
9 booleans can be packed into 2 byte and 8 long need 32 byte, 34 byte. Using one hole byte per boolean, yes 41.
EEPROM.begin(9*sizeof(boolean)+8*sizeof(long));
Railroader:
9 booleans can be packed into 2 byte and 8 long need 32 byte, 34 byte. Using one hole byte per boolean, yes 41.
"One hole byte"!
It certainly is!
Paul__B:
"One hole byte"!It certainly is!
I don't remember the environtment but except for long, int, word, char, byte etc somewhere I've used bit, saving bytes....
You can only read and write bytes at a minimum.
You can manipulate individual bits in a byte, you might think of that as a form of compression, having 8 booleans effectively in one byte location.
if (digitalRead (pin2) == LOW){
// save it at byte0, bit 0:
byte0 = byte0 & 0xb11111110; // bit-wise AND in a 0 clears a bit, rest are left alone
}
if (digitalRead (pin3) == HIGH){
// save it at byte0, bit 1:
byte0 = byte | 0b00000010; // bit-wise OR in a 1 sets a bit, rest are left alone
}
There are probably fancier ways to accomplish the same too.
See Bitwise Operators
CrossRoads:
You can only read and write bytes at a minimum.
You can manipulate individual bits in a byte, you might think of that as a form of compression, having 8 booleans effectively in one byte location.if (digitalRead (pin2 == LOW){
if (digitalRead (pin3 == HIGH){
What did You write in those if-statements? Does it compile.....?
if( digitalRead(true)....
if'(DigitalRead(false)....
true is defined as 1 and false as 0 I think.
Explain to me!
Yeah, left out a ) in the digitalRead. Should be set now.
I usually don't make that error.
byte pin2 = 2;
byte pin3 = 3;
byte byte0;
void setup() {
// put your setup code here, to run once:
if (digitalRead (pin2) == LOW){
// save it at byte0, bit 0:
byte0 = byte0 & 0xb11111110; // bit-wise AND in a 0 clears a bit, rest are left alone
}
if (digitalRead (pin3) == HIGH){
// save it at byte0, bit 1:
byte0 = byte0 | 0b00000010; // bit-wise OR in a 1 sets a bit, rest are left alone
}
}
void loop() {
// put your main code here, to run repeatedly:
}
And I didn't put any code there for putting it in EEPROM, just showing variable manipulation.
For the cause of OP.....
We are all human.... I didn't get it.....
Cheers!