Components and supplies
Standard LCD - 16x2 White on Blue
Arduino Micro
Rotary Encoder with Push-Button
Tools and machines
3D Printer (generic)
Apps and platforms
Arduino IDE
Project description
Code
The code
c_cpp
1#include <Keyboard.h> // 2#include <LiquidCrystal_I2C.h> // 3#include <EEPROM.h> 4#define pinA 5 // 5#define pinB 6 // 6#define btnPin 4 // 7 8byte aState; // 9byte bState; // 10byte aLastState; // 11int dir; //-1 - . ., 1 - . . 12byte attempt = 0; //- 13int pos = 0; // 14byte typed = 0; // 15bool accepted = false; // 16 17String code = "101"; // : 101 -- 110011 18int codeLen = 0; // 19String enter = ""; // 20 21int a = 0; // 22int len = 0; // 23int counter; 24 25byte address = 0; 26long currentTime; 27 28String passwords[][2] { 29 {"Admin", "eyamplepassword"}, 30 {"EPN", ""}, 31 {"Mail", ""}, 32 {"YouTube", ""}, 33 {"Asus", ";"}, 34 {"GMX", ""} 35}; 36 37LiquidCrystal_I2C lcd(0x3B, 16, 2); // 38 39int lcdClear(byte x) { // 40 if (x == 2) { //2 clear all, 0 clear first line, 1 clear second line 41 for (int i = 0; i < 2; ++i) { 42 lcd.setCursor(0, i); 43 lcd.print(" "); 44 } 45 } 46 else { 47 lcd.setCursor(0, x); 48 lcd.print(" "); 49 } 50} 51 52void setup() { 53 pinMode(pinA, INPUT); // - 54 pinMode(pinB, INPUT); // - 55 pinMode(btnPin, INPUT); // - 56 Serial.begin(9600); // 57 Keyboard.begin(); // 58 aLastState = digitalRead(pinA); // . 59 lcd.init(); // 60 lcd.backlight(); // 61 lcd.setCursor(0, 0); 62 lcd.print("<Password Typer>"); 63 lcd.setCursor(1, 1); 64 lcd.print("Version 1.6 PM"); 65 delay(3000); 66 lcdClear(2); 67 while (passwords[a][0] != NULL) { 68 a++; 69 len++; 70 } 71 //Serial.println(len); 72} 73 74void getDirection() { 75 aState = digitalRead(pinA); // 76 if (aState != aLastState) { // ... 77 if (aState == digitalRead(pinB)) { // ... 78 //Serial.println("CCW 0"); // 79 dir = -1; // . . 80 } 81 else { 82 //Serial.println("CW 1"); // 83 dir = 1; // . . 84 } 85 } 86 aLastState = aState; // . 87} 88 89void convert() { // , 90 for (int k = 0; k < codeLen; k++) { 91 enter.remove(k, 1); 92 } 93} 94 95void check() { 96 if (enter == code) { 97 accepted = true; // 98 lcdClear(2); 99 lcd.setCursor(4, 0); 100 lcd.print("Welcome!"); 101 delay(2000); 102 lcdClear(2); 103 enter = ""; 104 typed = 0; 105 lcd.setCursor(0, 0); 106 lcd.print(">"); 107 lcd.print(passwords[pos][0]); 108 if (len > 1) { 109 lcd.setCursor(1, 1); 110 lcd.print(passwords[pos + 1][0]); 111 } 112 } 113 else { 114 attempt += 1; //- 115 if (attempt == 3) { 116 lcdClear(2); 117 lcd.setCursor(0, 0); 118 lcd.print("Wrong password!"); 119 lcd.setCursor(0, 1); 120 lcd.print("Wait 1 minute!"); 121 currentTime = millis(); 122 while (millis() - currentTime < 1000 * 60) { 123 currentTime = millis(); 124 EEPROM.update(address, 1); 125 } 126 EEPROM.update(address, 0); 127 attempt = 0; 128 lcdClear(2); 129 typed = 0; 130 } 131 else { 132 lcd.setCursor(7, 0); 133 lcd.print(" "); 134 lcd.setCursor(15, 1); 135 lcd.print(3 - attempt); 136 lcd.setCursor(7, 0); 137 } 138 accepted = false; // 139 enter = ""; 140 } 141} 142 143void loop() { 144 if (accepted == false) { 145 if (EEPROM.read(address) == 1) { 146 lcdClear(2); 147 lcd.setCursor(0,0); 148 lcd.print(" WAIT "); 149 delay(1000 * 30); 150 lcdClear(2); 151 EEPROM.update(address, 0); 152 delay(1000); 153 } 154 getDirection(); // 155 if (typed == 0) { 156 lcd.setCursor(0, 0); 157 lcd.print("Unlock:"); 158 lcd.setCursor(0, 1); 159 lcd.print("Attempts left: 3"); 160 typed = 1; 161 lcd.setCursor(7, 0); 162 } 163 if (dir != 0) { 164 if (dir == -1) { 165 enter = enter + "0"; 166 } 167 else { 168 enter = enter + "1"; 169 } 170 codeLen = enter.length(); // 171 if (codeLen % 2 == 0) { 172 lcd.print("*"); 173 } 174 dir = 0; 175 } 176 if (digitalRead(btnPin) == 0) { // ... 177 delay(300); 178 convert(); 179 check(); 180 } 181 } 182 183 else { 184 getDirection(); 185 if (dir == 1 || dir == -1) { 186 counter++; 187 if (counter % 2 == 0) { 188 counter = 0; 189 if (dir == 1) { 190 if (pos + 1 < len) { 191 if (pos % 2 == 0) { 192 pos++; 193 lcd.setCursor(0, 0); 194 lcd.print(" "); 195 lcd.setCursor(0, 1); 196 lcd.print(">"); 197 } 198 else { 199 pos++; 200 lcdClear(2); 201 lcd.setCursor(0, 0); 202 lcd.print(">"); 203 lcd.print(passwords[pos][0]); 204 if (pos + 1 <= len) { 205 lcd.setCursor(1, 1); 206 lcd.print(passwords[pos + 1][0]); 207 } 208 } 209 } 210 } 211 else { 212 if (pos - 1 >= 0) { 213 if (pos % 2 == 0) { 214 pos--; 215 lcdClear(2); 216 lcd.setCursor(0, 1); 217 lcd.print(">"); 218 lcd.print(passwords[pos][0]); 219 lcd.setCursor(1, 0); 220 lcd.print(passwords[pos - 1][0]); 221 } 222 else { 223 pos--; 224 lcd.setCursor(0, 1); 225 lcd.print(" "); 226 lcd.setCursor(0, 0); 227 lcd.print(">"); 228 } 229 } 230 } 231 } 232 dir = 0; 233 } 234 if (digitalRead(btnPin) == 0) { 235 delay(300); 236 Keyboard.print(passwords[pos][1]); 237 } 238 } 239} 240
The code
c_cpp
1#include <Keyboard.h> // 2#include <LiquidCrystal_I2C.h> // 3#include <EEPROM.h> 4#define pinA 5 // 5#define pinB 6 // 6#define btnPin 4 // 7 8byte aState; // 9byte bState; // 10byte aLastState; // 11int dir; //-1 - . ., 1 - . . 12byte attempt = 0; //- 13int pos = 0; // 14byte typed = 0; // 15bool accepted = false; // 16 17String code = "101"; // : 101 -- 110011 18int codeLen = 0; // 19String enter = ""; // 20 21int a = 0; // 22int len = 0; // 23int counter; 24 25byte address = 0; 26long currentTime; 27 28String passwords[][2] { 29 {"Admin", "eyamplepassword"}, 30 {"EPN", ""}, 31 {"Mail", ""}, 32 {"YouTube", ""}, 33 {"Asus", ";"}, 34 {"GMX", ""} 35}; 36 37LiquidCrystal_I2C lcd(0x3B, 16, 2); // 38 39int lcdClear(byte x) { // 40 if (x == 2) { //2 clear all, 0 clear first line, 1 clear second line 41 for (int i = 0; i < 2; ++i) { 42 lcd.setCursor(0, i); 43 lcd.print(" "); 44 } 45 } 46 else { 47 lcd.setCursor(0, x); 48 lcd.print(" "); 49 } 50} 51 52void setup() { 53 pinMode(pinA, INPUT); // - 54 pinMode(pinB, INPUT); // - 55 pinMode(btnPin, INPUT); // - 56 Serial.begin(9600); // 57 Keyboard.begin(); // 58 aLastState = digitalRead(pinA); // . 59 lcd.init(); // 60 lcd.backlight(); // 61 lcd.setCursor(0, 0); 62 lcd.print("<Password Typer>"); 63 lcd.setCursor(1, 1); 64 lcd.print("Version 1.6 PM"); 65 delay(3000); 66 lcdClear(2); 67 while (passwords[a][0] != NULL) { 68 a++; 69 len++; 70 } 71 //Serial.println(len); 72} 73 74void getDirection() { 75 aState = digitalRead(pinA); // 76 if (aState != aLastState) { // ... 77 if (aState == digitalRead(pinB)) { // ... 78 //Serial.println("CCW 0"); // 79 dir = -1; // . . 80 } 81 else { 82 //Serial.println("CW 1"); // 83 dir = 1; // . . 84 } 85 } 86 aLastState = aState; // . 87} 88 89void convert() { // , 90 for (int k = 0; k < codeLen; k++) { 91 enter.remove(k, 1); 92 } 93} 94 95void check() { 96 if (enter == code) { 97 accepted = true; // 98 lcdClear(2); 99 lcd.setCursor(4, 0); 100 lcd.print("Welcome!"); 101 delay(2000); 102 lcdClear(2); 103 enter = ""; 104 typed = 0; 105 lcd.setCursor(0, 0); 106 lcd.print(">"); 107 lcd.print(passwords[pos][0]); 108 if (len > 1) { 109 lcd.setCursor(1, 1); 110 lcd.print(passwords[pos + 1][0]); 111 } 112 } 113 else { 114 attempt += 1; //- 115 if (attempt == 3) { 116 lcdClear(2); 117 lcd.setCursor(0, 0); 118 lcd.print("Wrong password!"); 119 lcd.setCursor(0, 1); 120 lcd.print("Wait 1 minute!"); 121 currentTime = millis(); 122 while (millis() - currentTime < 1000 * 60) { 123 currentTime = millis(); 124 EEPROM.update(address, 1); 125 } 126 EEPROM.update(address, 0); 127 attempt = 0; 128 lcdClear(2); 129 typed = 0; 130 } 131 else { 132 lcd.setCursor(7, 0); 133 lcd.print(" "); 134 lcd.setCursor(15, 1); 135 lcd.print(3 - attempt); 136 lcd.setCursor(7, 0); 137 } 138 accepted = false; // 139 enter = ""; 140 } 141} 142 143void loop() { 144 if (accepted == false) { 145 if (EEPROM.read(address) == 1) { 146 lcdClear(2); 147 lcd.setCursor(0,0); 148 lcd.print(" WAIT "); 149 delay(1000 * 30); 150 lcdClear(2); 151 EEPROM.update(address, 0); 152 delay(1000); 153 } 154 getDirection(); // 155 if (typed == 0) { 156 lcd.setCursor(0, 0); 157 lcd.print("Unlock:"); 158 lcd.setCursor(0, 1); 159 lcd.print("Attempts left: 3"); 160 typed = 1; 161 lcd.setCursor(7, 0); 162 } 163 if (dir != 0) { 164 if (dir == -1) { 165 enter = enter + "0"; 166 } 167 else { 168 enter = enter + "1"; 169 } 170 codeLen = enter.length(); // 171 if (codeLen % 2 == 0) { 172 lcd.print("*"); 173 } 174 dir = 0; 175 } 176 if (digitalRead(btnPin) == 0) { // ... 177 delay(300); 178 convert(); 179 check(); 180 } 181 } 182 183 else { 184 getDirection(); 185 if (dir == 1 || dir == -1) { 186 counter++; 187 if (counter % 2 == 0) { 188 counter = 0; 189 if (dir == 1) { 190 if (pos + 1 < len) { 191 if (pos % 2 == 0) { 192 pos++; 193 lcd.setCursor(0, 0); 194 lcd.print(" "); 195 lcd.setCursor(0, 1); 196 lcd.print(">"); 197 } 198 else { 199 pos++; 200 lcdClear(2); 201 lcd.setCursor(0, 0); 202 lcd.print(">"); 203 lcd.print(passwords[pos][0]); 204 if (pos + 1 <= len) { 205 lcd.setCursor(1, 1); 206 lcd.print(passwords[pos + 1][0]); 207 } 208 } 209 } 210 } 211 else { 212 if (pos - 1 >= 0) { 213 if (pos % 2 == 0) { 214 pos--; 215 lcdClear(2); 216 lcd.setCursor(0, 1); 217 lcd.print(">"); 218 lcd.print(passwords[pos][0]); 219 lcd.setCursor(1, 0); 220 lcd.print(passwords[pos - 1][0]); 221 } 222 else { 223 pos--; 224 lcd.setCursor(0, 1); 225 lcd.print(" "); 226 lcd.setCursor(0, 0); 227 lcd.print(">"); 228 } 229 } 230 } 231 } 232 dir = 0; 233 } 234 if (digitalRead(btnPin) == 0) { 235 delay(300); 236 Keyboard.print(passwords[pos][1]); 237 } 238 } 239} 240
Downloadable files
Schematic
Schematic
Schematic
Schematic
Documentation
Enclosure
Enclosure
Enclosure top
Enclosure top
Enclosure
Enclosure
Enclosure top
Enclosure top
Cap
Cap
Comments
Only logged in users can leave comments
mPelectronic
0 Followers
•0 Projects
Table of contents
Intro
22
0