Go Down

Topic: TFT Display Gate Opener Password (Read 1 time) previous topic - next topic

KonstantinBG

#15
Aug 19, 2018, 02:52 pm Last Edit: Aug 19, 2018, 02:55 pm by KonstantinBG
I have managed to get most of it to work but there are still a few unknowns which I am still trying to fix.

First of all is the problem with the password which I mentioned in my previous posts i.e. it accepts wrong passwords. Now the correct password is 1221 but it accepts 1111, 2221, 2121 and 2111 as well which is weird.

I set the comparison between the

Code: [Select]
userInput[4]
array and the

Code: [Select]
password[4]
array to occur when the ENTER button is pressed.

The next option I want to implement is that when I press ENTER to check if the password is correct it should go to a different screen showing a message saying the input password was correct or not respectively. If the password is correct a button called CLOSE should be on the new screen so when it is pressed the gate should start closing and the default keypad with the ENTER button should appear on the screen. Similarly, if the password is not correct a message should appear on the new screen and then go back to the screen with the keypad and the ENTER button.

I tried to implement that but when the new screens appears on the display the CLOSE button is not active for some reason and I am not sure what is the easiest way to go back to the previous screen showing the keypad and the ENTER button. I simply tried to initialize the buttons again and it works but probably there is an easier way to do that.


Here is the code. Everything before the

Code: [Select]
loop()
is the same as in the previous posts except that I added the CLOSE button variables.

Code: [Select]

/* two buttons are quite simple */
void loop(void)
{
    bool down = Touch_getXY();
    ONE_btn.press(down && ONE_btn.contains(pixel_x, pixel_y));
    TWO_btn.press(down && TWO_btn.contains(pixel_x, pixel_y));
    THREE_btn.press(down && THREE_btn.contains(pixel_x, pixel_y));
    FOUR_btn.press(down && FOUR_btn.contains(pixel_x, pixel_y));
    FIVE_btn.press(down && FIVE_btn.contains(pixel_x, pixel_y));
    SIX_btn.press(down && SIX_btn.contains(pixel_x, pixel_y));
    SEVEN_btn.press(down && SEVEN_btn.contains(pixel_x, pixel_y));
    EIGHT_btn.press(down && EIGHT_btn.contains(pixel_x, pixel_y));
    NINE_btn.press(down && NINE_btn.contains(pixel_x, pixel_y));
    ZERO_btn.press(down && ZERO_btn.contains(pixel_x, pixel_y));
    ENTER_btn.press(down && ENTER_btn.contains(pixel_x, pixel_y));
   
     
        getButtons();
        ButtonPress();
       
        Serial.print(button);
        Serial.print("\n");
        Serial.print(inputIndex);
        Serial.print("\n");
        Serial.print("\n");
        Serial.print("\n");
        for(int u=0; u<4; u++)
        {
          Serial.print(userInput[u]);
        }
        Serial.print("\n");
        Serial.print("\n");
        Serial.print("\n");
        Serial.print(PasswordGood);
        Serial.print("\n");
        Serial.print("\n");
        Serial.print("\n");
       
        if(PasswordGood == 1)
        {
          Serial.println("Match");
          for(int i=0; i<4; i++)
          {
            userInput[i]=-1;
          }
          inputIndex=0;
          button = -1;
          PasswordGood = -1;
         
          tft.fillScreen(RED);
          CLOSE_btn.initButton(&tft,  160, 240, 100, 80, WHITE, CYAN, BLACK, "CLOSE", 2);
          CLOSE_btn.drawButton(false);
          CLOSE_btn.press(down && CLOSE_btn.contains(pixel_x, pixel_y));
          //delay(1000);
          if (CLOSE_btn.justPressed())
          {
             CLOSE_btn.drawButton(true);
         
             tft.fillScreen(BLACK);
             tft.fillRect(5, 10, 200, 80, WHITE);

             ENTER_btn.initButton(&tft,  265, 50, 100, 80, WHITE, CYAN, BLACK, "ENTER", 2);
             ONE_btn.initButton(&tft,  35, 140, 60, 60, WHITE, CYAN, BLACK, "1", 2);
             TWO_btn.initButton(&tft,  125, 140, 60, 60, WHITE, CYAN, BLACK, "2", 2);
             THREE_btn.initButton(&tft,  215, 140, 60, 60, WHITE, CYAN, BLACK, "3", 2);
             FOUR_btn.initButton(&tft,  35, 230, 60, 60, WHITE, CYAN, BLACK, "4", 2);
             FIVE_btn.initButton(&tft,  125, 230, 60, 60, WHITE, CYAN, BLACK, "5", 2);
             SIX_btn.initButton(&tft,  215, 230, 60, 60, WHITE, CYAN, BLACK, "6", 2);
             SEVEN_btn.initButton(&tft,  35, 320, 60, 60, WHITE, CYAN, BLACK, "7", 2);
             EIGHT_btn.initButton(&tft,  125, 320, 60, 60, WHITE, CYAN, BLACK, "8", 2);
             NINE_btn.initButton(&tft,  215, 320, 60, 60, WHITE, CYAN, BLACK, "9", 2);
             ZERO_btn.initButton(&tft,  125, 410, 60, 60, WHITE, CYAN, BLACK, "0", 2);
             DELETE_btn.initButton(&tft,  215, 410, 60, 60, WHITE, RED, BLACK, "C", 2);

             ONE_btn.drawButton(false);
             TWO_btn.drawButton(false);
             THREE_btn.drawButton(false);
             FOUR_btn.drawButton(false);
             FIVE_btn.drawButton(false);
             SIX_btn.drawButton(false);
             SEVEN_btn.drawButton(false);
             EIGHT_btn.drawButton(false);
             NINE_btn.drawButton(false);
             ZERO_btn.drawButton(false);
             ENTER_btn.drawButton(false);
             DELETE_btn.drawButton(false);
          }

          if (CLOSE_btn.justReleased())
          {
             CLOSE_btn.drawButton();
          }
         
        }
        else if(PasswordGood == 0)
        {
          Serial.println("Not Equal");
          for(int i=0; i<4; i++)
          {
            userInput[i]=-1;
          }
          inputIndex=0;
          button = -1;
          PasswordGood = -1;
        }
        Serial.print("\n");
        Serial.print("\n");
        Serial.print("\n");
        if(ENTER==true)
        {
          Serial.print("ENTER");
        }
        Serial.print("\n");
        Serial.print("\n");
        Serial.print("\n");
        delay(100);
}



int getButtons()
{
    if (ONE_btn.justReleased())
        {
          ONE_btn.drawButton();
          return(0);
        }
       
    if (ONE_btn.justPressed())
    {
        button=1;
        ONE_btn.drawButton(true);
        return(button);
    }

    if (TWO_btn.justReleased())
        {
          TWO_btn.drawButton();
          return(0);
        }
    if (TWO_btn.justPressed())
    {
        button=2;
        TWO_btn.drawButton(true);
        return(button);
    }

    if (ENTER_btn.justReleased())
        {
          ENTER=false;
          ENTER_btn.drawButton();
        }
       
    if (ENTER_btn.justPressed())
    {
        ENTER=true;
        ENTER_btn.drawButton(true);
        cmpArray();
    }
}

void ButtonPress()
{
  //read which button was pressed, you'll have to write this part
  int btnpressed = getButtons();
  if (btnpressed != 0)
  {
    userInput[inputIndex] = btnpressed;
    inputIndex++;
    if (inputIndex > 3)
    {
     inputIndex = 0;
    }
  }
}

void cmpArray()
{
  for (int i = 0;  i < 4; i++)
{
    if( userInput[i] != password[i] )
    {
      //set your boolean flag here
      PasswordGood = 0;
    }
    else
    {
      PasswordGood = 1;
    }
}
}
#endif

KonstantinBG

#16
Aug 19, 2018, 04:11 pm Last Edit: Aug 19, 2018, 04:13 pm by KonstantinBG
The problem with the incorrect password is still occurring.

I managed to get the CLOSE button to work but some new weird thing are happening now.

First of all when I press the ENTER button to check if the input password is correct the screen is changing but the ENTER button is still appearing on the new screen which is not supposed to happen.

Next, the CLOSE button is working but for some reason the display detects that it is pressed twice and therefore the default screen with the keypad appears once then it goes down and then it reappears again.
When the default screen is stable if I touch the place where the CLOSE button is it appears again and I am able to press it and the same situation with reappearing again.

Basically the CLOSE button is supposed to appear to be active only if the password is correct and the screen has been changed.

I tried to compare the

Code: [Select]
userInput[4]

array with the

Code: [Select]
password[4]
array when the ENTER button has been released in order not to have the ENTER button in the new screen but unfortunately it is not visible as long as it is not pressed.

The same with CLOSE button, I tried to go to the default screen when the CLOSE button has been released but still it is not visible as long as it is not pressed.


You can find the code attached since I exceed the character limit.

jremington

#17
Aug 19, 2018, 05:12 pm Last Edit: Aug 19, 2018, 05:13 pm by jremington
This code compares just the 4th character of the password and the input. The first 3 characters of each don't matter.
Code: [Select]
void cmpArray()
{
  for (int i = 0;  i < 4; i++)
{
    if( userInput[i] != password[i] )
    {
      //set your boolean flag here
      PasswordGood = 0;
    }
    else
    {
      PasswordGood = 1;
    }
}
}

KonstantinBG

This code compares just the 4th character of the password and the input. The first 3 characters of each don't matter.
Code: [Select]
void cmpArray()
{
  for (int i = 0;  i < 4; i++)
{
    if( userInput[i] != password[i] )
    {
      //set your boolean flag here
      PasswordGood = 0;
    }
    else
    {
      PasswordGood = 1;
    }
}
}

I think I have managed to fix it by doing this.

Code: [Select]
void cmpArray()
{
  for (byte i = 0;  i < 4; i++)
{
    if( userInput[i] != password[i] )
    {
      //set your boolean flag here
      PasswordGood = 0;
      break;
    }
    else
    {
      PasswordGood = 1;
    }
}
}

KonstantinBG

#19
Dec 24, 2018, 09:18 pm Last Edit: Dec 24, 2018, 09:24 pm by KonstantinBG
Update on the project.

I am trying to get the motors to work utilizing the arduino relay board and the inductive PNP (NO) proximity sensors.

What I am trying to achieve is that the door starts to open until it reaches and activates the proximity sensor. Then the door should stop and reverse until the sensor is deactivated.

The issue is that when I put a metal object to the proximity sensor the reaction is very slow and the door will hit and break the sensor. But when I remove the metal object the reaction is immediate and the motor stops.

The relay board is with 12V coils.
The proximity sensors are powered with 12V as well and a voltage divider is used to make the voltage 5V which goes to the arduino digital input.

I use two relays to make the motor go forward and reverse:
Code: [Select]
relay1
and
Code: [Select]
relay2
The third relay
Code: [Select]
relay3
switches a signal lamp on when the motor is activated.

The code does the following - the motor and the lamp indicator are switched on. If a high input from the proximity sensor is detected the motor and the indicator stop and the motor direction is reversed until the proximity sensor is deactivated and then the motor stops.


You can find the code attached.

Code: [Select]

int relay1 = 22;
int relay2 = 23;
int relay3 = 52;


void setup()
{
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(32, INPUT);
  //Serial.begin(9600);
}

void loop()
{
  delay(5000);
 
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, LOW);


 
 
  if(digitalRead(32) == HIGH)
  {
    digitalWrite(relay1, HIGH);
    digitalWrite(relay2, HIGH);
    digitalWrite(relay3, HIGH);
    do
    {
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, LOW);
    }while(digitalRead(32) == HIGH);
   
    if(digitalRead(32)== LOW)
    {
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, HIGH);
    }
  }
}

Go Up