first of all im so sorry about the first post that i deleted and here is the post again ![]()
i need help with my project im making a time lapse machine that controls the camera and 3 servos for movement the thing is im stuck in the middle i have this menu code which is not yet complete to have all menus but it is a sample :
#include <stdio.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 14, 9, 4, 5, 6, 7);
// ==========
// hardware settings
#define rightKey 0
#define upKey 1
#define downKey 2
#define leftKey 3
#define selectKey 4
#define NUM_KEYS 5
// =====
// Program parameters
#define minShots 1
#define maxShots 9999
int valueShots = 15;
#define minTime 1
#define maxTime 99
int valueTime = 10;
#define programMode1 0
#define programMode2 1
#define programMode3 2
int programMode = programMode1;
boolean inMainProgram = false;
int programmSequence = 0;
#define sequenceModeSelect 0
#define sequenceModeOption 1
#define sequenceModeProgram 2
// first menu line - description of menu level
char sequenceHeader[3][17] = {"Mode select ", "Option select ", "Program start "};
// second menu line - mode select
char sequenceModes[4][17] = {" Camera >", "< Yaw >", "< Slide >", "< Pitch >"};
// second menu line - options settings
char sequenceOptions[4][17] = {"Shots: ", "YDegree: ", "SDegree: ", "PDegree: "};
void setup()
{
// initial lcd display while initialize and pc detection
lcd.clear();
lcd.print(" AAMS TECH ");
programmSequence = sequenceModeSelect;
inMainProgram = false;
delay(3000);
updateScreen();
}
// main loop with new key detection
int keyEvent = -1;
int lastEvent = -1;
int countEvent = 0;
//Key message
char msgs[5][3] = {
"> ",
"^ ",
"v ",
"< ",
"* " };
void updateScreen()
{
lcd.clear();
lcd.print(sequenceHeader[programmSequence]);
lcd.setCursor(0,1);
switch(programmSequence)
{
case sequenceModeSelect:
menuModeSelect( keyEvent );
break;
case sequenceModeOption:
menuOptionSelect( keyEvent );
break;
case sequenceModeProgram:
break;
}
}
void loop()
{
int keyEvent = detectKey();
if (keyEvent >= 0)
{
switch (keyEvent)
{
case upKey:
if (!inMainProgram)
{
if (programmSequence > sequenceModeSelect)
programmSequence--;
updateScreen();
}
break;
case downKey:
if (!inMainProgram)
{
if (programmSequence < sequenceModeProgram)
programmSequence++;
updateScreen();
}
break;
case rightKey:
case leftKey:
if (!inMainProgram)
{
switch (programmSequence)
{
case sequenceModeSelect:
menuModeSelect( keyEvent );
break;
case sequenceModeOption:
menuOptionSelect( keyEvent );
break;
case sequenceModeProgram:
break;
}
}
break;
case selectKey:
lcd.setCursor(0, 1);
if (lastEvent != keyEvent)
{
lastEvent = keyEvent;
countEvent=0;
}
else
countEvent++;
lcd.print(msgs[keyEvent]);
lcd.print(countEvent);
break;
}
}
}
// ===========
// Menu tools
void menuModeSelect( int keyEvent )
{
switch (keyEvent)
{
case rightKey:
if (programMode < programMode3)
programMode++;
break;
case leftKey:
if (programMode > programMode1)
programMode--;
break;
}
lcd.setCursor(0,1);
lcd.print( sequenceModes[programMode] );
}
void menuOptionSelect( int keyEvent )
{
char cbuf[4] = " ";
lcd.setCursor(0,1);
lcd.print(sequenceOptions[programMode]);
switch (keyEvent)
{
case rightKey:
switch (programMode)
{
case programMode1:
if (valueShots < maxShots)
valueShots++;
break;
case programMode2:
if (valueTime < maxTime)
valueTime++;
break;
}
break;
case leftKey:
switch (programMode)
{
case programMode1:
if (valueShots > minShots)
valueShots--;
break;
case programMode2:
if (valueTime > minTime)
valueTime--;
break;
}
break;
}
switch(programMode)
{
case programMode1:
if (valueShots > minShots)
lcd.print("<");
else
lcd.print(" ");
sprintf(cbuf,"%3d",valueShots);
lcd.print(cbuf);
if (valueShots < maxShots)
lcd.print(">");
else
lcd.print(" ");
break;
case programMode2:
if (valueTime > minTime)
lcd.print("<");
else
lcd.print(" ");
sprintf(cbuf,"%2d",valueTime);
lcd.print(cbuf);
if (valueTime < maxTime)
lcd.print(">");
else
lcd.print(" ");
break;
}
}
// ===================================================================
// Lcd tools
void clearLine(int line)
{
lcd.setCursor(0,line);
lcd.print(" ");
lcd.setCursor(0,line);
}
// =======
// Define a custom char in lcd
int defineCharacter(int ascii, int *data) {
int baseAddress = (ascii * smiley-cool + 64;
// baseAddress = 64 | (ascii << 3);
lcd.command(baseAddress);
for (int i = 0; i < 8; i++)
lcd.write(data);
lcd.command(128);
return ascii;
}
// ===================================================================
// Convert ADC value to key number
int adc_key_val[NUM_KEYS] ={ 30, 150, 360, 535, 760 };
int get_key(unsigned int input)
{
int k;
for (k = 0; k < NUM_KEYS; k++)
{
if (input < adc_key_val[k])
return k;
}
if (k >= NUM_KEYS)
k = -1; // No valid key pressed
return k;
}
// ========
// new key detection routine, without delays!
int lastKeyEvent = 0;
int curKeyEvent = 0;
int keyToReturn = 0;
boolean keyToProcess = false;
int adc_key_in = 0;
int detectKey()
{
keyToReturn = -1;
adc_key_in = analogRead(0); // read the value from the sensor
curKeyEvent = get_key(adc_key_in); // convert into key press
if (curKeyEvent != lastKeyEvent)
{
if (!keyToProcess)
{
lastKeyEvent = curKeyEvent;
keyToProcess = true;
}
else
{
keyToReturn = lastKeyEvent;
lastKeyEvent = -1;
keyToProcess = false;
}
}
return keyToReturn;
}
i need this to simply control servos and camera shutter, i need it to take the values that i will enter in the keypad shield and use them to control the servos and camera shutter