Initial commit
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,32 @@
|
||||
#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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,59 @@
|
||||
#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...
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
|
||||
// Edge Test For use with the DANGER SHIELD
|
||||
|
||||
// This code turns a LED on and incraments number displayed on the 7-segment display
|
||||
// whenever either PB1 or PB2 is pressed. PB1 used the debounce library and PB2 does
|
||||
// not. PB1 will cleanly increment the displayed value. PB2 will not alway increment
|
||||
// the display because the switch is not debounced.
|
||||
//
|
||||
// The bounce library also detects the rising or falling edge of the input.
|
||||
// This is often called a one-shot and is usefull if you want something to only
|
||||
// happen once when a button is pressed or released. The risingEdge method is true
|
||||
// for only one scan when the input goes from off-to-on. The fallingEdge method is
|
||||
// true for only one scan when the input goes from on-to-off. Even if you are not
|
||||
// using the debounce feature the the library you need to call the update method
|
||||
// every scan for the edge detection to work.
|
||||
//
|
||||
// Notes:
|
||||
// The buttons on the Danger Shield pull the input to ground when they are pressed,
|
||||
// so they act like normally closed switches. If order to make them work like one
|
||||
// would expect, he tests for the button states are reversed. This also reversesd
|
||||
// the rising edge test on button1 to a falling edge test.
|
||||
//
|
||||
// Since PB2 is not debounced, the edge detection is done directly in the sketch.
|
||||
//
|
||||
|
||||
|
||||
#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 BUTTON1 10
|
||||
#define BUTTON2 11
|
||||
#define BUTTON3 12
|
||||
|
||||
#define BUZZER 3
|
||||
|
||||
#define LED1 5
|
||||
#define LED2 6
|
||||
|
||||
#define LATCH 7
|
||||
#define CLOCK 8
|
||||
#define DATA 4
|
||||
|
||||
|
||||
// Shift register bit values to display 0-9 on the seven-segment display
|
||||
const byte ledCharSet[16] = {
|
||||
B00111111, B00000110, B01011011, B01001111, B01100110,
|
||||
B01101101, B01111101, B00000111, B01111111, B01101111,
|
||||
B01110111, // a
|
||||
B01111100, // b
|
||||
B00111001, // c
|
||||
B01011110, // d
|
||||
B01111001, // e
|
||||
B01110001 // f
|
||||
};
|
||||
|
||||
byte pressCount= 0;
|
||||
bool lastButton2;
|
||||
|
||||
// Instantiate a Bounce object with a 5 millisecond debounce time
|
||||
Bounce bouncer1 = Bounce(BUTTON1, 5);
|
||||
|
||||
void setup() {
|
||||
pinMode(BUTTON1, INPUT);
|
||||
pinMode(LED1, OUTPUT);
|
||||
|
||||
pinMode(BUTTON2, INPUT);
|
||||
pinMode(LED2, OUTPUT);
|
||||
|
||||
pinMode(BUTTON3, INPUT);
|
||||
pinMode(BUZZER, OUTPUT);
|
||||
|
||||
pinMode(LATCH, OUTPUT);
|
||||
pinMode(CLOCK, OUTPUT);
|
||||
pinMode(DATA, OUTPUT);
|
||||
|
||||
lastButton2 = digitalRead(BUTTON2);
|
||||
|
||||
displayDigit(255, true);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
// Update debouncer
|
||||
boolean button1Changed = bouncer1.update();
|
||||
|
||||
// Turn on or off the LED
|
||||
if ( !bouncer1.read()) {
|
||||
digitalWrite(LED1, HIGH);
|
||||
} else {
|
||||
digitalWrite(LED1, LOW);
|
||||
}
|
||||
|
||||
int buttonValue2 = digitalRead(BUTTON2);
|
||||
if (buttonValue2 == LOW) {
|
||||
digitalWrite(LED2, HIGH);
|
||||
} else {
|
||||
digitalWrite(LED2, LOW);
|
||||
}
|
||||
|
||||
if ( bouncer1.fallingEdge() || // rising edge of button 1
|
||||
(lastButton2 && !buttonValue2)) { // rising edge of button 2
|
||||
displayDigit(pressCount, false);
|
||||
pressCount++;
|
||||
if (pressCount > 15) { pressCount = 0; }
|
||||
}
|
||||
|
||||
lastButton2 = digitalRead(BUTTON2);
|
||||
|
||||
}
|
||||
|
||||
void displayDigit(byte value, boolean dp) {
|
||||
byte shiftData = 0;
|
||||
if (value <= 15) { shiftData = ledCharSet[value]; }
|
||||
if (dp) { shiftData |= B10000000; }
|
||||
digitalWrite(LATCH,LOW);
|
||||
shiftOut(DATA, CLOCK, MSBFIRST, ~shiftData);
|
||||
digitalWrite(LATCH,HIGH);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
||||
#include <Bounce.h>
|
||||
|
||||
// As long as the button is held down, the LED will blink
|
||||
// Build the circuit indicated here: http://arduino.cc/en/Tutorial/Button
|
||||
|
||||
#define BUTTON 2
|
||||
#define LED 13
|
||||
|
||||
// A variable to store the current LED state
|
||||
int ledState = LOW;
|
||||
|
||||
// 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 and monitor a change of input
|
||||
if ( bouncer.update() ) {
|
||||
|
||||
// Get the state of the button
|
||||
int value = bouncer.read();
|
||||
|
||||
// Toggle the LED if the button is held
|
||||
if ( value == HIGH) {
|
||||
// Make the button retrigger in 500 milliseconds
|
||||
bouncer.rebounce(500);
|
||||
if ( ledState == LOW ) {
|
||||
ledState = HIGH;
|
||||
} else {
|
||||
ledState = LOW;
|
||||
}
|
||||
} else {
|
||||
ledState = LOW;
|
||||
}
|
||||
|
||||
digitalWrite(LED, ledState );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user