0

I want to control the speed and position of stepper motor by a 4*4 keypad and monochrome graphic lcd interfaced with arduino. some open sources gave me good hint points to start controlling the distance and the speed of the stepper motor . I have made some modifications on the code in order to use it in both controlling the speed of motor and distance. I expect from the code either to:

1- change the position from 1 line to another and change the value at each parameter and see it on the graphic screen.

2- To change the page of the graphic lcd and modify each parameter separately in each page.

[I tried to code the first option but I faced the problem of changing the line to the next parameter without changing the written value, and that was a bit hard to me.] The code contains of functions that changes the pressed keypad signal to a readable number to be able to draw it in the lcd, then these functions are called by case statements.

I have modified the code to have a number string for each parameter separated from the other one.

When I modified the loop code (as cleared below), I have seen that when I press 'A' or 'B' for the first time, one of the parameters screen is shown on the screen and the loop of this parameter is activated, and I can not change the parameter by pressing the other button. This is because of the While loop [While(1)] which frames me in one of the buttons loops forever. When I remove this loop, the case statements are no longer valid, I just see the change in the screen but I can not add or remove any number. So that I tried to change it this loop with other options like: while( keypressed == 'A') or [do -- while(0)] or if statements, but no results on the screen. this is the part of the code.

void loop()
{

char keypressed = customKeypad.getKey();  // Get value of keypad button if pressed

if (keypressed != NO_KEY)     // If keypad button pressed check which key it was
{ 
    if (keypressed == 'A') 
    {
        Serial.println("A");
        draw3();
        while(1)
        {
            char key1 = customKeypad.getKey();
            if (key1 !=NO_KEY)
            {  
                switch (key1)
                {
                    case '1':
                        checknumber(1);
                        break;
                    case '2':
                        checknumber(2);
                        break;
                    case '3':
                        checknumber(3);
                        break;
                    case '4':
                        checknumber(4);
                        break;
                    case '5':
                        checknumber(5);
                        break;
                    case '6':
                        checknumber(6);
                        break;
                    case '7':
                        checknumber(7);
                        break;
                    case '8':
                        checknumber(8);
                        break;
                    case '9':
                        checknumber(9);   
                        break;
                    case '0':
                        checknumber(0);
                        break;
                    case '*':
                        deletenumber();
                        break;
                    case'#':
                        calculatedistance();
                        break;
                    }
                }
            }
        }
        if (keypressed == 'B')
        {
            draw4();
            Serial.println('B');
            while(1)
            {
                char key1 = customKeypad.getKey();
                if (key1 !=NO_KEY) 
                {  
                    switch (key1)
                    {
                        case '1':
                            checknumber(1);
                            break;
                        case '2':
                            checknumber2(2);
                            break;
                        case '3':
                            checknumber2(3);
                          break;
                        case '4':
                            checknumber2(4);
                            break;
                        case '5':
                            checknumber2(5);
                            break;
                        case '6':
                            checknumber2(6);
                            break;
                        case '7':
                            checknumber2(7);
                            break;
                        case '8':
                            checknumber2(8);
                            break;
                        case '9':
                            checknumber2(9);   
                            break;
                        case '0':
                            checknumber2(0);
                            break;
                        case '*':
                            deletenumber2();
                            break;
                        case'#':
                           stepperspeed();
                           break;
                        }
                    }
                }
            }
        }
    }
  • this looks like an exact same question that has been asked very recently .... are you asking this question again? ... is this a school assignment? – jsotola Jun 14 at 17:51
  • note: because of their simplicity, the switch blocks would actually be more readable if you single-lined the case statements ... like so case '1': checknumber(1); break; ... line up the command lines into neat columns – jsotola Jun 14 at 18:23
  • Seems like you have three tasks: 1. reading the keypad 2. writing the lcd 3. controlling the stepper. Which of those is the problem? Asking for help in all of them is too broad to answer in my opinion. – Sim Son Jun 14 at 19:04
  • I just changed the location of the question from robotics to arduino to be more feasible. I already discovered that I already have more than 1 issue to talk about because as you say there is more than 1 task. If I solved the first part between the LCD and the keypad, I think that the rest of controlling the stepper will not be a problem, as designing a graphic layout is the most harsh part in the coding. anyway I have changed the method. if you are interested, check my 2nd question and I will be grateful if you helped me to answer it. – romento Jun 16 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.