Last active
June 4, 2018 21:01
-
-
Save giltesa/807b04bf098291ccc2efc610db696edf to your computer and use it in GitHub Desktop.
Arduino: Obfuscate LCD characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://twitter.com/giltesa/status/1003716194778714115 | |
#include <LiquidCrystal.h> | |
#include <MultiTaskLib.h> | |
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); | |
MultiTask multitask(20); | |
const byte ROW = 1; | |
void setup() | |
{ | |
lcd.begin(16, 2); | |
lcd.print("Enter password:"); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
static byte col = 0; | |
static char btn; | |
multitask.Update(); | |
btn = readButton(); | |
if( btn != '#' ) | |
{ | |
lcd.setCursor(col, ROW); | |
lcd.print(btn); | |
uint8_t var = multitask.AddSingle(1000, [](){ obfusChar(col); }); | |
Serial.print("ID = "); | |
Serial.println(var); | |
col = (col+1 < 16 ? col+1 : 0); | |
} | |
} | |
void obfusChar( const byte col ) | |
{ | |
Serial.print("COL = "); | |
Serial.println(col); | |
lcd.setCursor(col, ROW); | |
lcd.print("*"); | |
} | |
char readButton() | |
{ | |
char result = '#'; | |
int val = analogRead(0); | |
if( val < 50 ) | |
result = 'R'; | |
else if( val < 250 ) | |
result = 'U'; | |
else if( val < 450 ) | |
result = 'D'; | |
else if( val < 650 ) | |
result = 'L'; | |
else if( val < 850 ) | |
result = 'S'; | |
while( result != '#' && analogRead(0) < 1000 ); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://twitter.com/giltesa/status/1003743414192615424 | |
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); | |
String password = ""; | |
const byte ROW = 1; | |
char btn; | |
void setup() | |
{ | |
lcd.begin(16, 2); | |
lcd.print("Enter password:"); | |
} | |
void loop() | |
{ | |
btn = readButton(); | |
if( btn != '#' ) | |
{ | |
byte length = password.length(); | |
if( length <= 15 ) | |
{ | |
password.concat(btn); | |
for( int i=0 ; i <= length ; i++ ) | |
{ | |
lcd.setCursor(i, ROW); | |
lcd.print(i < length ? '*' : password.charAt(i)); | |
} | |
} | |
} | |
} | |
char readButton() | |
{ | |
char result = '#'; | |
int val = analogRead(0); | |
if( val < 50 ) | |
result = 'R'; | |
else if( val < 250 ) | |
result = 'U'; | |
else if( val < 450 ) | |
result = 'D'; | |
else if( val < 650 ) | |
result = 'L'; | |
else if( val < 850 ) | |
result = 'S'; | |
while( result != '#' && analogRead(0) < 1000 ); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment