Does bitWrite() rewrite every bit in a variable or...

Hi everyone
So I'm trying to use the internal EEPROM of UNO to save the state of some LEDs and I've decided to use bitWrite in order to use the write cycles of the EEPROM as efficiently as possible , I just want to know if it's worth the trouble of using bitWrite. The question is would bitWrite rewrite every single bit in a byte of EEPROM and only change the one that we want or can it specifically target the very bit that it needs to change?

Thank you

EDIT : Nevermind it was a weird mistake I was making my brain just didn't register for some time :smiley:

Nevermind I wasn't understanding the exaple code that I got, now I do, this doesn't have anything to do with bitwrite itself, you'll have to use EEPROMwrite anyways so the byte is updated

byte EEPROMbyte = EEPROM.read(EEPROMaddress);
bitWrite(EEPROMbyte, pinBit, pinState);
EEPROM.update(EEPROMaddress, EEPROMbyte);

bitWrite is basically a read modify write. Therefore if any bits change it has to write all of the bits. There are some processors that do it on a bit by bit basis for I/o and internal registers, but not all. None I know of do it to memory.
Why not use the EEPROMex library then just use the update command, if nothing changes no writes take place.
Good Luck & Have Fun!
Gil

Yes that's exactly what's happening in the code I found, I don't know why I didn't get it. Rookie mistake I guess :slight_smile:
Thank you for the response

Why not use the EEPROMex library then just use the update command

Why not use the normal EEPROM library update() function ?

gilshultz:
bitWrite is basically a read modify write. Therefore if any bits change it has to write all of the bits.

Given: PORTD contains 10101010.
According to the above quote, this instruction: bitWrite(PORTD, 4, HIGH); is the compact form of the following codes:

byte x = PORTD;
x = x | 0b00010000;
PORTD = x;

This is the first time I have heard that bitWrite() is a read-modify-write operation which is found in 8051 architecture.