Hi everybody!
My first days of Arduino was a living hell. But that’s over now
But I wan’ t to share my first project, because i’ve searched for a lot of examples for this and couldn’t find anything.
Creating a keypad on the ARLcd touchscreen
(it just sends a digital out for now to relais and maglock).
The code could probably use some cleaning up (just finished). A lot of thing could have been simpler.
But it works :).
Hope somebody can enjoy this without the 2 days of misery it cost me.
Next step. Connecting the Arduino to escaperoom controller software. (hoping I get it done in a week)
//pascode door opener using EZLCD
#include <ezLCDLib.h>
#define LED_PIN 13
ezLCD3 lcd;
int x1Pos = 10;
int x2Pos = 80;
int x3Pos = 150;
int x4Pos = 220;
int y1Pos = 30;
int y2Pos = 100;
int y3Pos = 170;
int width = 60;
int height = 60;
int radius = 5;
int alignment = 0; // 0=centered, 1=right, 2=left, 3=bottom, 4=top
int option = 1; // 1=draw, 2=disabled, 3=toggle pressed, 4=toggle not pressed,
// 5=toggle pressed disabled, 6=toggle not pressed disabled.
int result= 0;
int touch=0;
int t=0;
int i=0;
int var[4];
int test[2]={1,1};
int pas[4]={1,2,3,4};
void setup() {
lcd.begin( EZM_BAUD_RATE );
lcd.cls( BLACK, WHITE );
lcd.font("0");
lcd.xy("ct");
lcd.printString("POWER ROOM\" \"ct");
lcd.string( 1, "1" ); // stringId 1
lcd.string( 2, "2" ); // stringId 2
lcd.string( 3, "3" ); // stringId 3
lcd.string( 4, "4" ); // stringId 3
lcd.string( 5, "5" );
lcd.string( 6, "6" );
lcd.string( 7, "7" );
lcd.string( 8, "8" );
lcd.string( 9, "9" );
lcd.string( 10, "0" );
lcd.string( 20, "Enter pascode");
lcd.button( 1, x1Pos, y1Pos, width, height, option, alignment, radius, 3, 1 );
lcd.button( 2, x2Pos, y1Pos, width, height, option, alignment, radius, 3, 2 );
lcd.button( 3, x3Pos, y1Pos, width, height, option, alignment, radius, 3, 3 );
lcd.button( 4, x4Pos, y1Pos, width, height, option, alignment, radius, 3, 4 );
lcd.button( 5, x1Pos, y2Pos, width, height, option, alignment, radius, 3, 5 );
lcd.button( 6, x2Pos, y2Pos, width, height, option, alignment, radius, 3, 6 );
lcd.button( 7, x3Pos, y2Pos, width, height, option, alignment, radius, 3, 7 );
lcd.button( 8, x4Pos, y2Pos, width, height, option, alignment, radius, 3, 8 );
lcd.button( 9, x1Pos, y3Pos, width, height, option, alignment, radius, 3, 9 );
lcd.button( 10, x2Pos, y3Pos, width, height, option, alignment, radius, 3, 10 );
lcd.color( WHITE );
lcd.xy( 120, 55 );
//void staticText( int ID, int x, int y, int width, int height, int option, int theme, int stringID);
lcd.staticText( 20, 153, 170, 120, 60, 8, 1, 20 );
pinMode( LED_PIN, OUTPUT );
digitalWrite( LED_PIN, HIGH );
}
void check()
{
lcd.wstack(0);//this will update currentWidget, currentInfo, currentData
if (( lcd.currentWidget == 1 ) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 1;
delay(50);
}
else
if (( lcd.currentWidget == 2 ) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 2;
delay(50);
}
else
if (( lcd.currentWidget == 3 ) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 3;
delay(50);
}
else
if (( lcd.currentWidget == 4 ) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 4;
delay(50);
}
else
if (( lcd.currentWidget == 5 ) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 5;
delay(50);
}
else
if (( lcd.currentWidget == 6 ) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 6;
delay(50);
}
else
if (( lcd.currentWidget == 7 ) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 7;
delay(50);
}
else
if (( lcd.currentWidget == 8) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 8;
delay(50);
}
else
if (( lcd.currentWidget == 9 ) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 9;
delay(50);
}
else
if (( lcd.currentWidget == 10 ) && ( lcd.currentInfo==PRESSED )) // if Button 1 is pressed:
{touch = 10;
delay(50);
}
}
void maskcode()
{
switch(i)
{
case 1:
lcd.wvalue( 20, "*" );
break;
case 2:
lcd.wvalue( 20, "**" );
break;
case 3:
lcd.wvalue( 20, "***" );
break;
case 4:
lcd.wvalue( 20, "****" );
break;
}
}
void loop()
{
lcd.wstack(2);
i=0;
while(i<=3)
{
touch = 0;
t=lcd.touchS();
if (t=2)
{
check();
switch (touch)
{
case 1:
var[i] = 1;
i=i+1;
maskcode();
break;
case 2:
var[i] = 2;
i++;
maskcode();
break;
case 3:
var[i] = 3;
i++;
maskcode();
break;
case 4:
var[i] = 4;
i++;
maskcode();
break;
case 5:
var[i] = 5;
i++;
maskcode();
break;
case 6:
var[i] = 6;
i++;
maskcode();
break;
case 7:
var[i] = 7;
i++;
maskcode();
break;
case 8:
var[i] = 8;
i++;
maskcode();
break;
case 9:
var[i] = 4;
i++;
maskcode();
break;
case 10:
var[i] = 0;
i++;
maskcode();
break;
}
}
}
if (i=4)
{
if (var[0]== pas[0] && var[1]== pas[1] && var[2]== pas[2] && var[3]== pas[3])
{
lcd.wvalue( 20, "Door open" );
digitalWrite( LED_PIN, LOW );
}
else
{
lcd.wvalue( 20, "Incorrect" );
delay(1000);
lcd.wvalue( 20, "Try again!");
i=0;
t=0;
}
}
delay(10);
}