Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 26, 2012
@lazyatom lazyatom Removing dependency on Bounce library saves 190 bytes.
I've copied the implementation of a software debouncer from the
Arduino website[1]. Using Arduino 1.0.1, before this commit the
sketch size is 29,906 bytes, and after it is 29,716 bytes.

However, the main benefit of this commit is that no non-standard
libraries are required to compile the sketch.

[1]: http://arduino.cc/playground/Learning/SoftwareDebounce
1c0aa09
Showing with 25 additions and 5 deletions.
  1. +25 −5 printer.ino
View
30 printer.ino
@@ -4,7 +4,6 @@
#include <EEPROM.h>
#include <SoftwareSerial.h>
-#include <Bounce.h>
// -- Settings for YOU to change if you want
@@ -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 {

No commit comments for this range

Something went wrong with that request. Please try again.