Skip to content

Commit

Permalink
Merge branch 'evil-twin'
Browse files Browse the repository at this point in the history
  • Loading branch information
mxzz committed Jul 29, 2024
2 parents 5d7745f + 5c4e15a commit 60e041a
Show file tree
Hide file tree
Showing 6 changed files with 482 additions and 310 deletions.
91 changes: 91 additions & 0 deletions buttons.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//Buttons functions

Button2 buttonUp;
Button2 buttonDown;
Button2 buttonLeft;
Button2 buttonRight;
Button2 buttonA;
Button2 buttonB;


void buttonsInit()
{
//change your pins configurations
buttonA.begin(2);
buttonA.setID(2);
buttonB.begin(0);
buttonB.setID(0);
buttonLeft.begin(16);
buttonLeft.setID(16);
buttonUp.begin(14);
buttonUp.setID(14);
buttonDown.begin(12);
buttonDown.setID(12);
buttonRight.begin(13);
buttonRight.setID(13);

buttonA.setPressedHandler(buttonPressed);
buttonB.setPressedHandler(buttonPressed);
buttonLeft.setPressedHandler(buttonPressed);
buttonRight.setPressedHandler(buttonPressed);
buttonUp.setPressedHandler(buttonPressed);
buttonDown.setPressedHandler(buttonPressed);
}

void buttonLoops() {
if (digitalRead(flashButtonPin) == LOW) {
delay(50);
if (digitalRead(flashButtonPin) == LOW) {
displayClearDisplay();
displayPrintln("Flash button pressed. WiFiManager settings...");
wifiManager.resetSettings();
displayPrintln("EEPROM and WiFiManager settings erased.");
displayPrintln("Restart this device");
delay(10000);
ESP.restart();
}
}
}

bool readButton(int pin, unsigned long debounceDelay = 10) {
static int lastButtonState = HIGH;
static int buttonState = HIGH;
static unsigned long lastDebounceTime = 0;

int reading = digitalRead(pin);

if (reading != lastButtonState) {
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
lastButtonState = reading;
return true; // Button is pressed
}
}
}

lastButtonState = reading;
return false; // Button is not pressed
}


void controlsButtonLoop()
{
buttonA.loop();
buttonB.loop();
buttonUp.loop();
buttonDown.loop();
buttonLeft.loop();
buttonRight.loop();
}


// Function to handle button press event
void buttonPressed(Button2 &btn) {

SerialPrintLn(String(btn.getID()));
}
22 changes: 22 additions & 0 deletions faces.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

void drawnetgotchiFace(int state) {
displaySetCursor(30 + moveX, 30);
if (evilTwinDetected) {
netgotchiCurrentFace = netgotchiFaceEvilTwin;
} else if (honeypotTriggered) {
if (state == 0) netgotchiCurrentFace = netgotchiFaceSad;
if (state == 1) netgotchiCurrentFace = netgotchiFaceSad2;
if (state == 2) netgotchiCurrentFace = netgotchiFaceSuspicious;
if (state == 3) netgotchiCurrentFace = netgotchiFaceSuspicious2;
if (state == 4) netgotchiCurrentFace = netgotchiFaceHit;
if (state == 5) netgotchiCurrentFace = netgotchiFaceHit2;
} else {
if (state == 0) netgotchiCurrentFace = netgotchiFace;
if (state == 1) netgotchiCurrentFace = netgotchiFace2;
if (state == 2) netgotchiCurrentFace = netgotchiFaceBlink;
if (state == 3) netgotchiCurrentFace = netgotchiFaceSleep;
if (state == 4) netgotchiCurrentFace = netgotchiFaceSurprised;
if (state == 5) netgotchiCurrentFace = netgotchiFaceHappy;
}
displayPrintln(netgotchiCurrentFace);
}
Loading

0 comments on commit 60e041a

Please sign in to comment.