Arduino Mega with DFRobot 16x2 LCD keypad shield time lapse 2

first of all im so sorry about the first post that i deleted and here is the post again :slight_smile:
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

Ok, that’s all fine and good but you need to state your situation more clearly.
You have outlined your intentions but have said nothing about your progress or current situation.
Maybe you should read ‚ÄúHow to use this forum‚ÄĚ because this is not a game of 20 Questions.
We should not have to ask you ‚ÄúHave you done this‚Ķ? etc.‚ÄĚ
At this point we have no idea why you are posting. We don’t know if the problem is electrical or software
or what. You need to state the problem clearly.
IF the problem is HW related we will probably need a photo of your wiring.
I have a feeling you are just asking for SW help but that is just a hunch based on your comments about
menus.

  1. What have you tried ?
  2. What were your observations ?
  3. Do you have a specific question ?
  4. We need to know what is ‚Äúgoing on‚ÄĚ with your program. (ie: have you run it? Did it compile ? etc‚Ķ)
    How about you give us a proper SITREP (MILSPEAK for SITUATION REPORT) ?

the thing is im stuck in the middle

What does this mean ? What do you want from us ? (so your stuck in the middle. Ok. so what ? What do you need help with ?)

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

This is not a SPECIFICATION for a program. If you asking us to COMPLETE your program, we need to know the CRITERIA

ok lets say the first choice in the menu which is camera i set the number to 10 that means 10 shots i need a code to make the loop that takes this input and start working on it by clicking on select on the board

is that clear ?, im sorry if you are upset with my posting but i will try to be more clarified

You need to read my last posting and make a list of all the questions and answer them all. (like , have you tested any code ? etc... What are the criteria (ie: for the camera : what is the timing criteria ? (pulse width etc..) Making a loop that outputs 10 pulses with delays between them is simple. We need to know if anything in your program works (does it compile, even if it is incomplete ?) You need to give us a SITREP. Have you , or have not tried to compile the program or run it ? No one is upset, but a breadcrumb here or there is really not sufficient. What is the SITREP ?

1- yes i tried the program compiled it and uploaded it to arduino mega and it works fine the menu is ok 2- it is not that i want a loop to output pulses is easy yes but the 10 is just an example the number depends on what i will input from the LCD keypad shield so the program should be like : Menu: -camera _ -shots = 10 or 20 etc. "depends on the input while the LCD is running and im making an input using the buttons" -time = 5 sec " that means between shots there are 5 seconds time" now these inputs are examples of how i will work and now when i click ( select ) on the keypad the program takes these inputs and run them in the loop and when i click on select again the program stops

You are just input values for variables that are already defined such that :
[VAR_NAME_01]=INPUT | Where ‚ÄúINPUT‚ÄĚ = KEYBOARD_READ(KEYBOARD) etc‚Ķ
So , where are you ‚ÄúSTUCK‚ÄĚ ?
Robert

I found that your ascii character programming could be wrong

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;
}
and could not get the program to start the program
i am using a arduino mega 2560 do you have any other problems with it

You might at least tell us (everyone else that is, since I already noticed it) that you are using either the Sainsmart Keypad Shield or the LinkSprite keypad shield, and post a link to the vendor of your shield where the schematic can be found.

You need to give us a SITREP.

I have a similar keypad shield at home and an UNO. I'll try your code if I have time.

What kind of arduino are you using that has a pin 14 ?

 LiquidCrystal lcd(8, 14, 9, 4, 5, 6, 7);

Post a link to the keypad shield if you want help. I need to see the documentation for that.