I'm new to this Arduino thing...so forgive me if there's anything wrong with the code or my concept. Any suggestions or alternate ways to do the same thing would be great.
I'm working on a project that will need to read and store a number of values ( as integers -- milliseconds from 0 to 1000 or so) to be used in a photo delay trigger. I decided in needed 10 values for the various delays so I was simply going to have a bunch of pots to allow me to dial in the values I wanted, read these as the sketch ran, and use them in the delay loops. So I realized I'd use up all those ports which I didn't really want to do.
In my testing of this POT vs switches idea, I've found it to be much easier than having to deal with the odd-ball values that the switch/voltage divider schemes come up with. It's just a nice clean 0-10 set of values.
- I want to have a pot let me set the delay value .. from 0-1023
- I want to store the values in Eprom once they are selected.
I've set up a 10k pot from +5v to gnd, and the wiper on an analog pin.
and a second 10k pot from +5v to gnd, and the wiper on another analog pin.
There's also a 'save setting' SP/NO pushbutton switch connected to a digital port.
When the menu select pot is at '0' (basically grounded) the sketch decides that is not in 'programming mode'. As soon as the pot moves out of 0 ohms the program will start reading it and decided at what point the wiper is at giving values from 0 to 1023.
(code tags added by moderator)
int menuSelectPot = 0; // pot wiper connected to analog pin 0
int valueSelectPot = 0; // pot wiper connected to analog pin 1
int saveSettingSwitch = 8; // switch to 'capture' the current setting if the
// menu is on.
int myMenu=0; // value to store which menu is currently selected
int settingValue = 0; // variable to store the read value
void setup()
{
pinMode(menuSelectPot, INPUT);
pinMode(valueSelectPot, INPUT);
pinMode(saveSettingSwitch, INPUT);
readSettings();
}
void readSettings()
{
// for now this is just a dummy function
// it will read the 10 stored settings
// from eProm and put them in an array
// and store them as integers in an array of 10 positions
}
void loop()
{
//read the pot -- values will be from 0 to 1023
//convert to values from 0 to 10 simply by dividing by 100
myMenu = analogRead(menuSelectPot)/100;
//display the results on the lcd...
doMenuDisplay(myMenu);
}
void doMenuDisplay(int menu)
{
if (menu > 0 )
{
lcd.print("Menu is ON: ");
delay(1000);
// ... at this point 2 things will happen...
//show the value on the screen
settingValue = analogRead(menuValuePot);
lcd.Print('Menu #');
lcd.Print(myMenu);
lcd.Print(" Value:");
lcd.Println(settingValue);
//check to see if we have pushed the save setting button
if (digitalRead(saveSettingSwitch)==HIGH)
{
// save the value to an eprom location
//
// not coded yet ....
//
delay(500); // just to give us time to insure the setting is saved and our
// finger is off the save button.
// will probably put a status message on the lcd to confirm save of the setting
delay(1500);
}
}
else
{
lcd.Println('Menu OFF');
}
}