Storing variables

Hey everyone

I'm in the process of building a cruise conteol system for my jeep using an arduino mega (i know its probly overkill for this project but i wanted to be sure i had enough digital inputs)

I am very new at c++ and what i need is programing advice

I need a way to have the arduino store a value with a button press and modofy it with other buttons and have the code reference this value to detetmine how far to move the servo motor (throttle) is there any way i can do this with c++

Thank you everyone

Welcome to the forum

Leaving aside the wisdom of using an Arduino for cruise control of a vehicle, where are you stuck ?

Do you know how to read the state of an input ?
Do you know how to determine that the state of an input has changed ?
How will the user know the value that has been entered ?
Does the value entered need to be available after a reboot or shutdown ?
How will the value be used by the vehicle to set the speed to cruise at ?

Absolutely it can be done. Your mega has EEPROM storage as well as Flash memory so you can use that to read/write your value and it will be retained across power cycles. Look at the EEPROM library which is part of the standard install. There are examples in the IDE.

Yes i know how to read digital inputs in this case will be a frequency value from a vehicle speed sensor, and no i dont need it to remember that value... what im stuck with is what code command i should use to store the "set" value when i hit the "set" button so i can heve the arduino referece that value and determine weather the throttle needs to be opened or closed based on currant speed

There is not a single command that will store a value but you have not said exactly how you expect the user to enter the value

Suppose that you only had 3 set speeds available. You could count the number of button presses and set a variable to the speed depending on the number of presses made

if (pressCount == 1)
{
  speed = 30;
}
else if (pressCount == 2)
{
  speed = 40;
}
else if (pressCount == 3)
{
  speed = 50;
}

Is that the sort of thing that you had in mind, or something else ?

Where is the value coming from that you want to store when you press the button?

if (setButtonPressed)
    setValue = programmedValue;

Its a digital square wave frequency from a haul effect vehicle speed sensor

I have 4 buttons... one will be the "set" value, "increase speed" "decrease speed" and "cancle" which will be tied to the break peddle as well

That is entirely a different kettle of fish. It seems that you want to measure the current speed and set the cruise speed to the current speed on press of a button. Is that the aim of the project and, if so, do you know how to measure the frequency of the input ?

Yes!!! This is exactly what i want... and i havent figured out the exact coding for measuring freqeny but i do know its possible

Good, we are now getting somewhere. However, until you can measure the frequency no further progress is possible

Have you tried to read the output from the speed sensor ?

Yes but all i can get it to fo is count the pulses not measure the frequency i know im still learning

If you count the pulses received in a known timeframe then you can calculate the frequency

Ok so thats just a simple algorithm but how do get it to remember that value with a button press?

See post #6

Wont that constantly be trying to increase speed though?

You push the button once, the frequency you calculated is stored once. There is nothing there to increase anything.

Lets suppose that you read the pulses and calculate the frequency and save it in a variable named programmedValue

Now see post #6

if (setButtonPressed)
    setValue = programmedValue;

I will have to try that when i get home thank you ill let you know my reaults!!

I will try that when i get hone thank you for the advice