Storing a value

jucasan:
What I'm doing wrong?

_Assuming _ you want to save the brightness value when the Arduino is shut off, you need to understand that calling something brightnessMemory does not mean it will be saved when power goes away. It's like any other variable stored in RAM, it's lost when power is removed.

You need to store the value of brightnessMemory in the onboard EEPROM before shutdown and then retrieve that value upon powerup, usually in setup().