programming attiny85

I have been trying to figure out how to program the attiny85 and use the on board eeprom. I just need a sample code to build off of. I am using a push button on pin 2, and LEDs on pins 1 and 0. I am trying to program flashpatterns that will hold when power is off. can anyone write a sample code that I can build off of? thanks for the help!!

Nothing on the internet could help?

arduino attiny85 eeprom

I haven't found anything on what I am trying to do. I can write different flash patterns. But I have not found anything on how to make the chip hold memory when power is disconnected or change patterns. Like I said I have just been copying and modifying code to get it to work so far so I am still learning.

I still haven't found anything yet they give me a quick insight on how to utilize the EEPROM. I'm trying to develop a police light for an RC car that I can change a couple patterns on with a momentary pushbutton. And it will keep the pattern that I have chosen when I disconnect the power and turn it back on.

Do you understand how flash, SRAM, and EEPROM memory are used and their characteristics?

No I don't sorry. I can just do basic programminglikeblinking LEDs. I'm kind of good at taking code and modifying it and playing around with it to make it do stuff. But I have not found anything on changing a flash pattern with A momentary pushbutton that reads and writes from the EEPROM when the power is disconnected on and aTtiny 85

So you can start by reading about flash, SRAM, and EEPROM memory and how to write in EEPROM and practice with simple examples.

Wow! I am learning that there is a lot about programming that I do not know. I am a hands-on physical learner. It is hard for me to read and retain information. Are there any recommendations on YouTube videos or audio books on basics of programming that will start me from the beginning and teach me from start to finish? Not necessarily the entire programming process but where I need to go for what I am trying to do? Thank you guys for the help I would still like it if somebody had a demo code to work off of with a couple different patterns in it. That way I can visually see what I am learning while I am reading it.

All I am trying to do is build an police RC car with a couple different flash patterns that I can change with the momentary pushbutton. But I need it to retain the memory of the pattern when the power is switched off. I am using a aTtiny85. The momentary pushbutton is on pin two and the LEDs are on pin zero and one. Again thank you guys for all of the help.

You can't alter the EPROM contents without power.
Without talking in terms of programming, how do you imagine all of this, your objectives, would be accomplished with just one pushbutton (as input)?

My ultimate goal is wall power is applied and you have a set flash pattern for the RC police car when you press the momentary button it changes to a different flash pattern but when power is disconnected I wanted to stay on the flash pattern that you have chosen that's what I'm trying to do with the EEPROM. I'm sorry that it sounded like I was trying to make changes without power applied. I know I have to write a code that says when the button is pressed to change to this pattern when the button is pressed again change to the next pattern when the button is pressed again change to the next pattern and so on

Your chip has flash memory that keeps the program and its embedded data in secured memory even when your device is powered off. If you declare your flashing sequence as arrays values then you have nothing to do - it will be there when you power on and ready to be executed

J-M-L:
Your chip has flash memory that keeps the program and its embedded data in secured memory even when your device is powered off. If you declare your flashing sequence as arrays values then you have nothing to do - it will be there when you power on and ready to be executed

I think that you misunderstood what he's trying to achieve:-

when you press the momentary button it changes to a different flash pattern but when power is disconnected I wanted to stay on the flash pattern that you have chosen

He needs to store a variable in EEPROM that indicates the previous flash pattern on startup.

OldSteve:
arduino attiny85 eeprom

What a laugh!! I bookmarked that one :wink:

brice3010:
What a laugh!! I bookmarked that one :wink:

It's a handy reminder sometimes. :slight_smile:

OldSteve:
I think that you misunderstood what he's trying to achieve:-He needs to store a variable in EEPROM that indicates the previous flash pattern on startup.

Forgot that indeed. Yes EEPROM then is a way to go. If he is on a budget, a dip switch might be also a simple option and easy user interface to select a sequence.

J-M-L:
Forgot that indeed. Yes EEPROM then is a way to go. If he is on a budget, a dip switch might be also a simple option and easy user interface to select a sequence.

Yep. I used to use BCD thumbwheels for this sort of thing, but that was a looong time ago.

I wish I could use the dip switches LOL but I am confined to space so I kind a need to figure out the code. I've been doing some searches online but haven't really come up with anything is there anybody out there that can help me with just a simple code with two patterns to choose from and I can do the rest ? Thank you for the help

Run this code once to initialize the EEPROM address 0

#include <EEPROM.h>

void saveSequenceNumber(byte b)
{
  EEPROM.update(0, b); // save b at address 0 in eeprom
}

void setup()
{
  saveSequenceNumber(5); // 5 will be our initial default value at start
}

void loop()
{
}

Then have your ‘real program’

#include <EEPROM.h>

void saveSequenceNumber(byte b)
{
  EEPROM.update(0, b); // save b at adrdess 0 in eeprom

  // An EEPROM write takes 3.3 ms to complete. The EEPROM memory has a specified life of 100,000
  // write/erase cycles, so using this function instead of write() can save cycles if the written data does
  // not change often
}

byte sequenceNumber()
{
  return EEPROM.read(0); // returns what is at address 0
}

void setup()
{
  Serial.begin(115200);
  if (sequenceNumber() == 5) {
    Serial.println("initial value - sequence is number 5");
    saveSequenceNumber(14); // change it for next run
  } else {
    Serial.print("sequence has been changed - number =");
    Serial.print(sequenceNumber());
  }
}


void loop()
{

}

The first time you run it, it will see 5 in EEPROM memory at address 0, will print the info and change it
Unplug your arduino or reset it and run it again
The second and further time you run the code, it will tell you it’s no longer the default value.

(Code not tested, just typed it on my smartphone)

Does this help?

(If you don’t want to have a special code to initialize the memory - given the EEPROM can have anything and you can’t know if it is from a previous run or not - a statistical decision making approach in the setup is to read about 5 bytes of EEPROM and see if there is a special message there like “Hello” - chances that it is there by mistake is kinda null. So If Hello is not there then write Hello and set your special initial value in memory at a known address. If Hello is already there then you know there is a default value at the known address and that your code was already run at least once on that chip.)

Joe479:
I wish I could use the dip switches LOL but I am confined to space so I kind a need to figure out the code. I've been doing some searches online but haven't really come up with anything is there anybody out there that can help me with just a simple code with two patterns to choose from and I can do the rest ? Thank you for the help

I assume you wanted to know which pattern to choose externally via some hardware option.
Is it possible to use a Jumper, connect the jumper like a push button switch. If jumper is in position you read a HIGH, if remove you read a LOW in one of your digital pin.
If HIGH choose a pattern and if LOW choose another pattern.

If its via Software, then use EEPROM. @JML already provided some snippets.