Permalink
Browse files

Changed folder structure as requested

  • Loading branch information...
thomasfredericks committed Jan 6, 2015
1 parent 2d5aedb commit 987d751bfa07e1d3f38bc09ffc3d52d6eece3800
View
Binary file not shown.
View
@@ -1,88 +0,0 @@
// Please read Bounce.h for information about the liscence and authors
#include "WProgram.h"
#include "Bounce.h"
Bounce::Bounce(uint8_t pin,unsigned long interval_millis)
{
interval(interval_millis);
previous_millis = millis();
state = digitalRead(pin);
this->pin = pin;
}
void Bounce::write(int new_state)
{
this->state = new_state;
digitalWrite(pin,state);
}
void Bounce::interval(unsigned long interval_millis)
{
this->interval_millis = interval_millis;
this->rebounce_millis = 0;
}
void Bounce::rebounce(unsigned long interval)
{
this->rebounce_millis = interval;
}
int Bounce::update()
{
if ( debounce() ) {
rebounce(0);
return stateChanged = 1;
}
// We need to rebounce, so simulate a state change
if ( rebounce_millis && (millis() - previous_millis >= rebounce_millis) ) {
previous_millis = millis();
rebounce(0);
return stateChanged = 1;
}
return stateChanged = 0;
}
unsigned long Bounce::duration()
{
return millis() - previous_millis;
}
int Bounce::read()
{
return (int)state;
}
// Protected: debounces the pin
int Bounce::debounce() {
uint8_t newState = digitalRead(pin);
if (state != newState ) {
if (millis() - previous_millis >= interval_millis) {
previous_millis = millis();
state = newState;
return 1;
}
}
return 0;
}
// The risingEdge method is true for one scan after the de-bounced input goes from off-to-on.
bool Bounce::risingEdge() { return stateChanged && state; }
// The fallingEdge method it true for one scan after the de-bounced input goes from on-to-off.
bool Bounce::fallingEdge() { return stateChanged && !state; }
View
@@ -1,70 +0,0 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
Main code by Thomas O Fredericks
Rebounce and duration functions contributed by Eric Lowry
Write function contributed by Jim Schimpf
risingEdge and fallingEdge contributed by Tom Harkaway
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef Bounce_h
#define Bounce_h
#include <inttypes.h>
class Bounce
{
public:
// Initialize
Bounce(uint8_t pin, unsigned long interval_millis );
// Sets the debounce interval
void interval(unsigned long interval_millis);
// Updates the pin
// Returns 1 if the state changed
// Returns 0 if the state did not change
int update();
// Forces the pin to signal a change (through update()) in X milliseconds
// even if the state does not actually change
// Example: press and hold a button and have it repeat every X milliseconds
void rebounce(unsigned long interval);
// Returns the updated pin state
int read();
// Sets the stored pin state
void write(int new_state);
// Returns the number of milliseconds the pin has been in the current state
unsigned long duration();
// The risingEdge method is true for one scan after the de-bounced input goes from off-to-on.
bool risingEdge();
// The fallingEdge method it true for one scan after the de-bounced input goes from on-to-off.
bool fallingEdge();
protected:
int debounce();
unsigned long previous_millis, interval_millis, rebounce_millis;
uint8_t state;
uint8_t pin;
uint8_t stateChanged;
};
#endif
View
@@ -1,13 +0,0 @@
Bounce library for Arduino
Version 1.5
by Thomas Ouellet Fredericks
with contributions from:
Eric Lowry
Jim Schimpf
Tom Harkaway
contact: mrtoftrash@gmail.com
See the online documentation here: http://www.arduino.cc/playground/Code/Bounce
@@ -1,32 +0,0 @@
#include <Bounce.h>
// This code turns a led on/off through a debounced button
// Build the circuit indicated here: http://arduino.cc/en/Tutorial/Button
#define BUTTON 2
#define LED 13
// Instantiate a Bounce object with a 5 millisecond debounce time
Bounce bouncer = Bounce( BUTTON,5 );
void setup() {
pinMode(BUTTON,INPUT);
pinMode(LED,OUTPUT);
}
void loop() {
// Update the debouncer
bouncer.update ( );
// Get the update value
int value = bouncer.read();
// Turn on or off the LED
if ( value == HIGH) {
digitalWrite(LED, HIGH );
} else {
digitalWrite(LED, LOW );
}
}
@@ -1,31 +0,0 @@
#include <Bounce.h>
#define BUTTON 2
#define LED 13
int ledValue = LOW;
// This example changes the state of the LED everytime the button is pushed
// Build the circuit indicated here: http://arduino.cc/en/Tutorial/Button
Bounce bouncer = Bounce( BUTTON, 5 );
void setup() {
pinMode(BUTTON,INPUT);
pinMode(LED,OUTPUT);
}
void loop() {
if ( bouncer.update() ) {
if ( bouncer.read() == HIGH) {
if ( ledValue == LOW ) {
ledValue = HIGH;
} else {
ledValue = LOW;
}
digitalWrite(LED,ledValue);
}
}
}
@@ -1,59 +0,0 @@
#include <Bounce.h>
/*
This example uses a mercury tilt switch to detect the orientation
of a robot. If you turn the bot over, it falls asleep to conserve
battery life. If you have ever used a tilt switch before,
you know they can be very "noisy" - they jump around a lot!
The bounce library can handle sensing when a noisy switch has
"settled down" with the "duration" method that tells you how long
the pin has been in the current state.
*/
const uint8_t ORIENTATION_PIN = 16;
Bounce orientation = Bounce( ORIENTATION_PIN, 50 );
int awake; // Are we awake based on our current orientation?
void setup() {
pinMode( ORIENTATION_PIN, INPUT );
digitalWrite( ORIENTATION_PIN, HIGH ); // Activate Pull-Up
Serial.begin(19200);
Serial.println( "Orientation Test " );
Serial.println();
awake = orientation.read();
Serial.println( awake ? "Awake!" : "Asleep!" );
}
unsigned long lastKnock = 0;
void loop() {
orientation.update();
// has our orientation changed for more the 1/2 a second?
if ( orientation.read() != awake && orientation.duration() > 500 ) {
awake = orientation.read();
if ( awake ) {
Serial.println( "Waking Up!" );
// Do Something Here...
}
else {
Serial.println( "Falling Asleep" );
// Do Something Here...
}
}
}
Oops, something went wrong.

0 comments on commit 987d751

Please sign in to comment.