Engineering Asked by Geo on January 21, 2021
So I’m new to using Arduino’s in general and just want to have my code by reversed each subsequent startup using the eeprom on my Arduino uno. I’ve been trying to read up on how to use the eeprom but I’m kind of confused so I’ve posted below a picture of some sample code that I think should work (but it’s probably wrong). Basically I want to on start-up, execute some code, and next startup it executes some other code (the reverse of the original. Then the next startup to execute the original code. I’m unsure of how to fit my Boolean system into the loop part though, so any help would be greatly appreciated!
So What I want this code to do is the first time I power the Arduino to print "Code A". Then after its shutdown, and restarted again to print "Code B" But what I get at the moment is
The problem is that during setup, you first write the EEPROM address to 1 and printA, and then you read the same address which is now 1 so the if condition is again true.
What you should use :
if(EEPROM.read(address)==0)
{
Serial.println('A');
EEPROM.write(address)==1;
} else {
{
Serial.println('B');
EEPROM.write(address)==0;
}
(Hopefully I explained clear enough the problem. I'am a bit distracted by the newsfeed).
Answered by NMech on January 21, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP