Created
March 6, 2017 23:32
-
-
Save c5e3/5d32e4a17524b2f0c1f9abe8ffd10eaf to your computer and use it in GitHub Desktop.
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
// thx @trollkopp for helping me optimizing the code | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_SSD1306.h> | |
// ARDUINO | |
#define OLED_MOSI 11 | |
#define OLED_CLK 12 | |
#define OLED_DC 9 | |
#define OLED_CS 8 | |
#define OLED_RESET 10 | |
// ESP8266 | |
/* | |
#define OLED_MOSI D3 | |
#define OLED_CLK D4 | |
#define OLED_DC D1 | |
#define OLED_CS D0 | |
#define OLED_RESET D2 | |
*/ | |
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); | |
void crackCode(int, int); | |
void drawFrame(); | |
void setup(){ | |
// ARDUINO | |
pinMode(13, OUTPUT); | |
digitalWrite(13, HIGH); | |
Serial.begin(115200); | |
randomSeed(analogRead(0)); | |
display.begin(SSD1306_SWITCHCAPVCC); | |
display.display(); | |
display.clearDisplay(); | |
drawFrame(); | |
display.display(); | |
} | |
char code[] = "CPE1704TKS"; | |
//char code[] = "JPE1704TKS"; // wrong code from one scene | |
//char code[] = "DLG2209TVX"; // launch code from opening scene | |
boolean flag[] = {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}; | |
char string[10]; | |
int cnt = 0; | |
int tres = 150; | |
int wait = 50; | |
//int order[] = {6, 1, 3, 5, 9, 2, 4, 0, 8, 7}; // actual order of code[] | |
//int order[] = {7, 1, 5, 2, 6, 3, 0, 9, 8, 4}; // sequence, when character gets set | |
void loop() { | |
sprintf(string, "%c%c%c%01i%01i%01i%01i%c%c%c", (char)random('A', 'Z'+1), (char)random('A', 'Z'+1), (char)random('A', 'Z'+1), (int)random(0, 9+1), (int)random(0, 9+1), (int)random(0, 9+1), (int)random(0, 9+1), (char)random('A', 'Z'+1), (char)random('A', 'Z'+1), (char)random('A', 'Z'+1)); | |
if ( cnt > tres ) { | |
// ______ for-loop wouldn't work | |
// / ____ flag value of previous value | |
// | / _ sequence number | |
// | | / | |
crackCode(0,4,7); | |
crackCode(1,6,1); | |
crackCode(2,9,5); | |
crackCode(3,1,2); | |
crackCode(4,2,6); | |
crackCode(5,3,3); | |
crackCode(6,6,0); | |
crackCode(7,8,9); | |
crackCode(8,0,8); | |
crackCode(9,5,4); | |
} | |
//sprintf(string, "CPE1704TKS"); | |
if ( !strcmp(string, code) ) { | |
display.clearDisplay(); | |
drawFrame(); | |
while (1) { | |
display.setCursor(4, (display.height() / 2) - 7); | |
display.setTextSize(2); | |
display.setTextColor(WHITE); | |
if (flag[10] == 0) { | |
display.print(code); | |
display.display(); | |
flag[10] = 1; | |
delay(500); | |
} else { | |
flag[10] = 0; | |
} | |
delay(250); | |
display.clearDisplay(); | |
drawFrame(); | |
display.display(); | |
} | |
} | |
display.clearDisplay(); | |
drawFrame(); | |
display.setCursor(4, (display.height() / 2) - 7); | |
display.setTextSize(2); | |
display.setTextColor(WHITE); | |
display.print(string); | |
//Serial.println(string); | |
display.display(); | |
delay(50); | |
if( cnt <= 10000 ) cnt++; | |
} | |
void crackCode(int i, int j, int k) { | |
if ((string[i] == code [i] || flag [i] == 1) && cnt>tres+wait*k && flag[j] == 1){ | |
string[i] = code[i]; | |
flag[i] = 1; | |
} | |
} | |
void drawFrame(){ | |
for(int i=0; i<3; i++){ | |
display.drawFastHLine(0, i, display.width()-1, WHITE); | |
} | |
for(int i=display.height()-1; i>display.height()-4; i--){ | |
display.drawFastHLine(0, i, display.width()-1, WHITE); | |
} | |
//display.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment