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++
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 ?
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 ?