Hi everyone. I have a little problem with the program below. When i press "6" program turns on and I can light on LEDs. When I press "6" once again, program turns off and I can't do anything with LEDs, and it's work asI want. My problem is the fact, that when i turn on three LEDs, and then I turn off all program, after switching it back on, the 3 LEDs should light up again.
Why not just start with all 3 LEDs on?
Just turn on all 3 in setup.
In this programm I decide how much LEDs I want to light on. 3 LEDs were only an example, because I can turn on two or four LEDs, it doesnt matter. The aim is remember, how much LEDs were light on before I turn off all program.
Why not just start with all 3 LEDs on?
Just turn on all 3 in setup.
[/quote]
Now, that is helpful, not what you said however.
Arduino – 5 – Storing Data in Arduino EEPROM Memory – HandsOn Tech
Google for more examples
Your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem ![]()
Where should I put this code in my program? Its a difficult task for me because I just started my arduino history.
I was trying to do something, but I don't know how to declare EEPROM reading when I click "8" button.
I was trying to do something, but I don't know how to declare EEPROM reading when I click "8" button.
I understand you are new with Arduino, but there are numerous examples; a 2-part solution:
- in setup() you are going to read the default/last saved values
- in your "8" section of code, you are going to write the current values into eeprom.
How To Save Values On Arduino With EEPROM - The Robotics Back-End (roboticsbackend.com)
So, in this forum, everyone is expected to research and write the code into their existing code on their own. If you have continued issues, you come back, post your most recently tried code and explain what issues you are experiencing. When you do your part, generally assistance is quick.
But do try to just use one of the EEPROM training examples first so you can understand the store/retrieve syntax and logic.
EEPROM Library | Arduino Documentation | Arduino Documentation
The aim is remember, how much LEDs were light on before I turn off all program.
Your original code only turned the LEDs on and off for the various button pushes and did not record anywhere how many LEDs were on. Try separating the two functions: Buttons set the number of LEDs to light when the LEDs are on:
void loop ()
{
if (irrecv.decode(&results))
{
unsigned long odczyt = results.value;
Serial.println (odczyt, HEX);
switch (odczyt)
{
case Button8:
activated = !activated; // Toggle power
break;
case 0xFF6897:
//Serial.println ("0");
LEDsLit = 0;
break;
case 0xFF30CF:
//Serial.println ("1");
LEDsLit = 1;
break;
case 0xFF18E7:
//Serial.println ("2");
LEDsLit = 2;
break;
case 0xFF7A85:
//Serial.println ("3");
LEDsLit = 3;
break;
case 0xFF10EF:
//Serial.println ("4");
LEDsLit = 4;
break;
}
}
digitalWrite (LED1, activated && (LEDsLit >= 1));
digitalWrite (LED2, activated && (LEDsLit >= 2));
digitalWrite (LED3, activated && (LEDsLit >= 3));
digitalWrite (LED4, activated && (LEDsLit >= 4));
irrecv.resume ();
}
I tried, but it doesn't work. Program doesn't remember the previous state of LEDs.
In setup(), you always turn the LEDs on and then read the state from EEPROM. You need to read the state and then use that value to set your LED on/off
on1 = EEPROM.read(1);
digitalWrite(LED1, on1);
...
How to declare reading eeprom after if(Burron8== odczyt)? I think, that here is the problem why program doesn't rememer the previous state of LEDs.
Hi, I have a problem with program.
Hi, I have a problem with program.
So you did not write a tutorial. Hence your topic has been moved to a more suitable location on the forum.
You only need to read from one location, and that location is one byte -256 combinations , you need 16.
So read from that location into a variable and use switch case to decode your lights .
If you change the light sequence , update that variable and save to eeprom . If it doesnt change , don’t save it .
Button 8 doesn't turn off the program (or the arduino), it turns off the LEDs and will ignore all IR commands except button 8 (which starts things up again). You only need EEPROM if you want the state of the LEDs to persist when you reset or remove power from the arduino.
Just save the current state of the LEDs when button 8 is pressed to turn them OFF, then when button 8 is pressed again to turn back ON restore the previous state of the LEDs.
Yes, that's the point, but I don't know how to proceed with this program.
Just save the current state of the LEDs when button 8 is pressed to turn them OFF, then when button 8 is pressed again to turn back ON restore the previous state of the LEDs.
How to write it and where put this code?
Perhaps, read the EEPROM tutorial at Arduino.cc? Look for EEPROM.put, EEPROM.get, and maybe EEPROM.begin. But seriously, do a little reading, and come back with questions if you need clarifications.
Well, I've read it, but when I'm going to put it into practice, it gets harder. Especially since the program is quite long, and I'm just starting to play with arduino.