Real Homework4.
This commit is contained in:
@@ -13,17 +13,17 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (Serial.available()) {
|
while (Serial.available()) {
|
||||||
char ch = Serial.read();
|
String input = Serial.readString();
|
||||||
Serial.print(ch);
|
Serial.print(input);
|
||||||
soft_serial.print(ch);
|
soft_serial.print(input);
|
||||||
}
|
}
|
||||||
if (soft_serial.available()) {
|
while (soft_serial.available()) {
|
||||||
char ch = soft_serial.read();
|
String input = soft_serial.readString();
|
||||||
Serial.print(ch);
|
Serial.print(input);
|
||||||
soft_serial.print(ch);
|
soft_serial.print(input);
|
||||||
}
|
}
|
||||||
Serial.println("A loop");
|
// Serial.println("A loop");
|
||||||
// Serial.println("A loop");
|
// Serial.println("A loop");
|
||||||
// if (soft_serial.availableForWrite()) {
|
// if (soft_serial.availableForWrite()) {
|
||||||
// Serial.println("Available");
|
// Serial.println("Available");
|
||||||
@@ -34,5 +34,5 @@ void loop() {
|
|||||||
// if (Serial.availableForWrite()) {
|
// if (Serial.availableForWrite()) {
|
||||||
// Serial.println("Can Write");
|
// Serial.println("Can Write");
|
||||||
// }
|
// }
|
||||||
delay(1000);
|
// delay(1000);
|
||||||
}
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#include "SoftwareSerial.h"
|
|
||||||
#include "U8glib.h"
|
|
||||||
|
|
||||||
const byte bt_tx_connected_to = 11;
|
|
||||||
const byte bt_rx_connected_to = 12;
|
|
||||||
|
|
||||||
String pass = "0721";
|
|
||||||
String recovery_pass
|
|
||||||
|
|
||||||
SoftwareSerial bt_serial(bt_tx_connected_to, bt_rx_connected_to);
|
|
||||||
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
Serial.begin(9600);
|
|
||||||
bt_serial.begin(9600);
|
|
||||||
u8g.setFont(u8g_font_courR08);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
draw_locked();
|
|
||||||
delay(1000);
|
|
||||||
draw_unlocked();
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_unlocked() {
|
|
||||||
u8g.firstPage();
|
|
||||||
do {
|
|
||||||
u8g.drawStr(0, 16, "Unlocked");
|
|
||||||
} while (u8g.nextPage());
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_locked() {
|
|
||||||
u8g.firstPage();
|
|
||||||
do {
|
|
||||||
u8g.drawStr(0, 8, "Locked");
|
|
||||||
} while (u8g.nextPage());
|
|
||||||
}
|
|
||||||
71
Homework/Homework4/Homework4/Homework4.ino
Normal file
71
Homework/Homework4/Homework4/Homework4.ino
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#include "SoftwareSerial.h"
|
||||||
|
#include "U8glib.h"
|
||||||
|
#define UNLOCKED 0
|
||||||
|
#define LOCKED 1
|
||||||
|
|
||||||
|
const byte rx_connected = 11;
|
||||||
|
const byte tx_connected = 10;
|
||||||
|
|
||||||
|
const String password = "0721";
|
||||||
|
const String reset_pass = "1145";
|
||||||
|
|
||||||
|
byte status = LOCKED;
|
||||||
|
|
||||||
|
String input = "";
|
||||||
|
|
||||||
|
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
|
||||||
|
|
||||||
|
SoftwareSerial soft_serial(tx_connected, rx_connected);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(tx_connected, INPUT);
|
||||||
|
pinMode(rx_connected, OUTPUT);
|
||||||
|
Serial.begin(9600);
|
||||||
|
soft_serial.begin(9600);
|
||||||
|
u8g.setFont(u8g_font_courR08);
|
||||||
|
draw_locked();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
while (soft_serial.available() && input.length() <= 4) {
|
||||||
|
input += soft_serial.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.length() < 4) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (status) {
|
||||||
|
case LOCKED:
|
||||||
|
if (input.substring(0, 4) == password) {
|
||||||
|
Serial.println("PASS");
|
||||||
|
status = UNLOCKED;
|
||||||
|
draw_unlocked();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.println("FAIL");
|
||||||
|
}
|
||||||
|
input = "";
|
||||||
|
break;
|
||||||
|
case UNLOCKED:
|
||||||
|
if (input.substring(0, 4) == reset_pass) {
|
||||||
|
status = LOCKED;
|
||||||
|
draw_locked();
|
||||||
|
}
|
||||||
|
input = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_unlocked() {
|
||||||
|
u8g.firstPage();
|
||||||
|
do {
|
||||||
|
u8g.drawStr(0, 16, "Unlocked");
|
||||||
|
} while (u8g.nextPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_locked() {
|
||||||
|
u8g.firstPage();
|
||||||
|
do {
|
||||||
|
u8g.drawStr(0, 8, "Locked");
|
||||||
|
} while (u8g.nextPage());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user