Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions printer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <EEPROM.h>

#include <SoftwareSerial.h>
#include <Bounce.h>

// -- Settings for YOU to change if you want

Expand Down Expand Up @@ -278,14 +277,35 @@ inline void printFromDownload() {
}


// -- Check for new data, print if the button is pressed.
byte counter = 0; // how many times we have seen new value
byte reading; // the current value read from the input pin
byte current_state = LOW; // the debounced input value
long timeOfLastSample = 0;

bool buttonPressed() {
if (millis() != timeOfLastSample) {
reading = digitalRead(buttonPin);
if (reading == current_state && counter > 0) {
counter--;
}
if (reading != current_state) {
counter++;
}
if (counter >= 5) {
counter = 0;
current_state = reading;
return true;
}
timeOfLastSample = millis();
}
return false;
}

Bounce bouncer = Bounce(buttonPin, 5); // 5 millisecond debounce
// -- Check for new data, print if the button is pressed.

void loop() {
if (downloadWaiting) {
bouncer.update();
if (bouncer.read() == HIGH) {
if (buttonPressed()) {
printFromDownload();
}
} else {
Expand Down