Store a variable from digital pins when Arduino turns off?

I have set up a rotary encoder to 2 digital pins. How do I store the position before turning the Arduino off?

I read the following 2 websites and the first says PROGMEM is hardly worth it for just one variable and the second website says EEPROMWrite is only good for analog data.

Thanks

You can only write to the EEPROM during run time.

It can store any data. The example is storing reads from the analog pins, you do not have to do this.

Progmem is to store constant data into flash during compile time.

bodkin77:
the first says PROGMEM is hardly worth it for just one variable

That's correct. But you can't store anything in PROGMEM during runtime...

bodkin77:
and the second website says EEPROMWrite is only good for aalog data.

Delete that website from your bookmarks. That's just a pile of crap :wink: Indeed, just store it in EEPROM.

But more important, how does the Arduino knows it needs to turn off?

the second website says EEPROMWrite is only good for analog data.

Nonsense. It says nothing of the sort.

bodkin77:
I have set up a rotary encoder to 2 digital pins. How do I store the position before turning the Arduino off?

I read the following 2 websites and the first says PROGMEM is hardly worth it for just one variable and the second website says EEPROMWrite is only good for analog data.

PROGMEM - Arduino Reference
https://www.arduino.cc/en/Tutorial/EEPROMWrite

Thanks

The EEPROM is perfect for what you want.

The PROGMEM (flash) is write protected in such a way that only the boot loader can write to it. So you can forget about that option.

Delta_G:
No, it's a good site, the OP just needs to learn how to read.

Yep, you're right. Be I'm pretty sure those links were not there when I answered so I just had to believe him when he said a site stated that. (Or I really was blind then :stuck_out_tongue: )

@stuart0, why on earth do you quote... Please use reply next time :wink:

But still the real problem exists, how does the Arduino knows when he needs to "turn off"?

Thanks 4 all the replies. If it didn't say "EEPROM is only for analog" then I must have read it elsewhere. Apologies for that bumsteer! Seems like the EEPROM is the way to go. I'll get to it after I send this msg.

But still the real problem exists, how does the Arduino knows when he needs to "turn off"?

The Arduino' power is being switched on via a PIR sensor and mosfet. While the loop counts to 300 I set a digital pin HIGH as output to feed current back to the mosfet gate via a resistor and transistor, keeping the mosfet (and Arduino) on until 300 is reached. It is this value that I will make variable.

If it indeed turns itself off then yes, you/it know(s) when it happens :slight_smile:

Tip, use EEPROM.update() instead of write() to possible some some unnecessary writes :slight_smile:

If it indeed turn itself off then yes, you know when it happens :slight_smile:

Tip, use EEPROM.update() instead of write() to possible some some unnecessary writes :slight_smile:

Are you by any chance replying on a 'phone or has someone else hijacked the account :slight_smile:

Sitting behind a desk, two monitors in front of me, one with Arduino IDE, the other with Firefox. Aka, no, not on a phone, why?

not on a phone, why?

The replies that I quoted looked like you were having difficulty typing joined up sentences, that's all.

Still had my native language hat on I guess xD

UKHeliBob:
The replies that I quoted looked like you were having difficulty typing joined up sentences, that's all.

hehe Bob. I could understand everything he was saying.

I understand because when I type a quick reply I often accidentally miss the odd word or two. It's funny sometimes when you read back something that you typed just a few minutes ago, and just one or two cases of incorrect tense or missing plural etc and it looks like you're a non English speaker, when in reality they're just simple typos.

I could understand everything he was saying.

I could understand what he tipped two but it not normal, hens my comment.

UKHeliBob:
I could understand what he tipped two but it not normal, hens my comment.

Yeah. I used to make a lot of mistakes, but these daze my spill chucker faxes everything four me. :wink:

spellcheck.jpg

spellcheck.jpg