Debounce (some) buttons
This commit is contained in:
		
							
								
								
									
										1
									
								
								lib/Bounce2/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								lib/Bounce2/.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1 +0,0 @@
 | 
				
			|||||||
*.db
 | 
					 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							@ -1,125 +0,0 @@
 | 
				
			|||||||
// Please read Bounce2.h for information about the liscence and authors
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "Bounce2.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const uint8_t DEBOUNCED_STATE = 0b00000001;
 | 
					 | 
				
			||||||
static const uint8_t UNSTABLE_STATE  = 0b00000010;
 | 
					 | 
				
			||||||
static const uint8_t CHANGED_STATE   = 0b00000100;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Bounce::Bounce()
 | 
					 | 
				
			||||||
    : previous_millis(0)
 | 
					 | 
				
			||||||
    , interval_millis(10)
 | 
					 | 
				
			||||||
    , state(0)
 | 
					 | 
				
			||||||
    , pin(0)
 | 
					 | 
				
			||||||
{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void Bounce::attach(int pin) {
 | 
					 | 
				
			||||||
    this->pin = pin;
 | 
					 | 
				
			||||||
    state = 0;
 | 
					 | 
				
			||||||
    if (readCurrentState()) {
 | 
					 | 
				
			||||||
        setStateFlag(DEBOUNCED_STATE | UNSTABLE_STATE);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#ifdef BOUNCE_LOCK_OUT
 | 
					 | 
				
			||||||
    previous_millis = 0;
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    previous_millis = millis();
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void Bounce::attach(int pin, int mode){
 | 
					 | 
				
			||||||
    setPinMode(pin, mode);
 | 
					 | 
				
			||||||
    this->attach(pin);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void Bounce::interval(uint16_t interval_millis)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    this->interval_millis = interval_millis;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool Bounce::update()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    unsetStateFlag(CHANGED_STATE);
 | 
					 | 
				
			||||||
#ifdef BOUNCE_LOCK_OUT
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    // Ignore everything if we are locked out
 | 
					 | 
				
			||||||
    if (millis() - previous_millis >= interval_millis) {
 | 
					 | 
				
			||||||
        bool currentState = readCurrentState();
 | 
					 | 
				
			||||||
        if ( currentState != getStateFlag(DEBOUNCED_STATE) ) {
 | 
					 | 
				
			||||||
            previous_millis = millis();
 | 
					 | 
				
			||||||
            toggleStateFlag(DEBOUNCED_STATE);
 | 
					 | 
				
			||||||
            setStateFlag(CHANGED_STATE);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#elif defined BOUNCE_WITH_PROMPT_DETECTION
 | 
					 | 
				
			||||||
    // Read the state of the switch port into a temporary variable.
 | 
					 | 
				
			||||||
    bool readState = readCurrentState();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if ( readState != getStateFlag(DEBOUNCED_STATE) ) {
 | 
					 | 
				
			||||||
      // We have seen a change from the current button state.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if ( millis() - previous_millis >= interval_millis ) {
 | 
					 | 
				
			||||||
	// We have passed the time threshold, so a new change of state is allowed.
 | 
					 | 
				
			||||||
	// set the STATE_CHANGED flag and the new DEBOUNCED_STATE.
 | 
					 | 
				
			||||||
	// This will be prompt as long as there has been greater than interval_misllis ms since last change of input.
 | 
					 | 
				
			||||||
	// Otherwise debounced state will not change again until bouncing is stable for the timeout period.
 | 
					 | 
				
			||||||
	 toggleStateFlag(DEBOUNCED_STATE);
 | 
					 | 
				
			||||||
     setStateFlag(CHANGED_STATE );
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // If the readState is different from previous readState, reset the debounce timer - as input is still unstable
 | 
					 | 
				
			||||||
    // and we want to prevent new button state changes until the previous one has remained stable for the timeout.
 | 
					 | 
				
			||||||
    if ( readState != getStateFlag(UNSTABLE_STATE) ) {
 | 
					 | 
				
			||||||
	// Update Unstable Bit to macth readState
 | 
					 | 
				
			||||||
        toggleStateFlag(UNSTABLE_STATE);
 | 
					 | 
				
			||||||
        previous_millis = millis();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    // Read the state of the switch in a temporary variable.
 | 
					 | 
				
			||||||
    bool currentState = readCurrentState();
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // If the reading is different from last reading, reset the debounce counter
 | 
					 | 
				
			||||||
    if ( currentState != getStateFlag(UNSTABLE_STATE) ) {
 | 
					 | 
				
			||||||
        previous_millis = millis();
 | 
					 | 
				
			||||||
         toggleStateFlag(UNSTABLE_STATE);
 | 
					 | 
				
			||||||
    } else
 | 
					 | 
				
			||||||
        if ( millis() - previous_millis >= interval_millis ) {
 | 
					 | 
				
			||||||
            // We have passed the threshold time, so the input is now stable
 | 
					 | 
				
			||||||
            // If it is different from last state, set the STATE_CHANGED flag
 | 
					 | 
				
			||||||
            if (currentState != getStateFlag(DEBOUNCED_STATE) ) {
 | 
					 | 
				
			||||||
                previous_millis = millis();
 | 
					 | 
				
			||||||
                 toggleStateFlag(DEBOUNCED_STATE);
 | 
					 | 
				
			||||||
                 setStateFlag(CHANGED_STATE) ;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
return  getStateFlag(CHANGED_STATE); 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool Bounce::read()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    return  getStateFlag(DEBOUNCED_STATE);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool Bounce::rose()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    return getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool Bounce::fell()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    return  !getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,110 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
  The MIT License (MIT)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  Copyright (c) 2013 thomasfredericks
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  Permission is hereby granted, free of charge, to any person obtaining a copy of
 | 
					 | 
				
			||||||
  this software and associated documentation files (the "Software"), to deal in
 | 
					 | 
				
			||||||
  the Software without restriction, including without limitation the rights to
 | 
					 | 
				
			||||||
  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 | 
					 | 
				
			||||||
  the Software, and to permit persons to whom the Software is furnished to do so,
 | 
					 | 
				
			||||||
  subject to the following conditions:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  The above copyright notice and this permission notice shall be included in all
 | 
					 | 
				
			||||||
  copies or substantial portions of the Software.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					 | 
				
			||||||
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 | 
					 | 
				
			||||||
  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 | 
					 | 
				
			||||||
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 | 
					 | 
				
			||||||
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 | 
					 | 
				
			||||||
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
 | 
					 | 
				
			||||||
  Main code by Thomas O Fredericks (tof@t-o-f.info)
 | 
					 | 
				
			||||||
  Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway
 | 
					 | 
				
			||||||
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef Bounce2_h
 | 
					 | 
				
			||||||
#define Bounce2_h
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if defined(ARDUINO) && ARDUINO >= 100
 | 
					 | 
				
			||||||
#include "Arduino.h"
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
#include "WProgram.h"
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Uncomment the following line for "LOCK-OUT" debounce method
 | 
					 | 
				
			||||||
//#define BOUNCE_LOCK_OUT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method
 | 
					 | 
				
			||||||
//#define BOUNCE_WITH_PROMPT_DETECTION
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <inttypes.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
#ifndef _BV
 | 
					 | 
				
			||||||
#define _BV(n) (1<<(n))
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Bounce
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 public:
 | 
					 | 
				
			||||||
    // Create an instance of the bounce library
 | 
					 | 
				
			||||||
    Bounce();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Attach to a pin (and also sets initial state)
 | 
					 | 
				
			||||||
    void attach(int pin);
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    // Attach to a pin (and also sets initial state) and sets pin to mode (INPUT/INPUT_PULLUP/OUTPUT)
 | 
					 | 
				
			||||||
    void attach(int pin, int mode);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Sets the debounce interval
 | 
					 | 
				
			||||||
    void interval(uint16_t interval_millis);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Updates the pin
 | 
					 | 
				
			||||||
    // Returns 1 if the state changed
 | 
					 | 
				
			||||||
    // Returns 0 if the state did not change
 | 
					 | 
				
			||||||
    bool update();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Returns the updated pin state
 | 
					 | 
				
			||||||
    bool read();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Returns the falling pin state
 | 
					 | 
				
			||||||
    bool fell();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Returns the rising pin state
 | 
					 | 
				
			||||||
    bool rose();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Partial compatibility for programs written with Bounce version 1
 | 
					 | 
				
			||||||
    bool risingEdge() { return rose(); }
 | 
					 | 
				
			||||||
    bool fallingEdge() { return fell(); }
 | 
					 | 
				
			||||||
    Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() {
 | 
					 | 
				
			||||||
        attach(pin);
 | 
					 | 
				
			||||||
        interval(interval_millis);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 protected:
 | 
					 | 
				
			||||||
    unsigned long previous_millis;
 | 
					 | 
				
			||||||
    uint16_t interval_millis;
 | 
					 | 
				
			||||||
    uint8_t state;
 | 
					 | 
				
			||||||
    uint8_t pin;
 | 
					 | 
				
			||||||
    virtual bool readCurrentState() { return digitalRead(pin); }
 | 
					 | 
				
			||||||
    virtual void setPinMode(int pin, int mode) {
 | 
					 | 
				
			||||||
#if defined(ARDUINO_STM_NUCLEO_F103RB) || defined(ARDUINO_GENERIC_STM32F103C)
 | 
					 | 
				
			||||||
        pinMode(pin, (WiringPinMode)mode);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
        pinMode(pin, mode);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  private:
 | 
					 | 
				
			||||||
    inline void setStateFlag(const uint8_t flag)    {state |= flag;}
 | 
					 | 
				
			||||||
    inline void unsetStateFlag(const uint8_t flag)  {state &= ~flag;}
 | 
					 | 
				
			||||||
    inline void toggleStateFlag(const uint8_t flag) {state ^= flag;}
 | 
					 | 
				
			||||||
    inline bool getStateFlag(const uint8_t flag)    {return((state & flag) != 0);}
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 16 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 9.1 KiB  | 
@ -1 +0,0 @@
 | 
				
			|||||||
Put the "Bounce2" folder in your Arduino or Wiring "libraries" folder. 
 | 
					 | 
				
			||||||
@ -1,20 +0,0 @@
 | 
				
			|||||||
The MIT License (MIT)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Copyright (c) 2013 thomasfredericks
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
 | 
					 | 
				
			||||||
this software and associated documentation files (the "Software"), to deal in
 | 
					 | 
				
			||||||
the Software without restriction, including without limitation the rights to
 | 
					 | 
				
			||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 | 
					 | 
				
			||||||
the Software, and to permit persons to whom the Software is furnished to do so,
 | 
					 | 
				
			||||||
subject to the following conditions:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
The above copyright notice and this permission notice shall be included in all
 | 
					 | 
				
			||||||
copies or substantial portions of the Software.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					 | 
				
			||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 | 
					 | 
				
			||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 | 
					 | 
				
			||||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 | 
					 | 
				
			||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 | 
					 | 
				
			||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
					 | 
				
			||||||
@ -1,37 +0,0 @@
 | 
				
			|||||||
BOUNCE 2
 | 
					 | 
				
			||||||
=====================
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Debouncing library for Arduino or Wiring
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
by Thomas Ouellet Fredericks
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
with contributions from:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Eric Lowry, Jim Schimpf, Tom Harkaway and Joachim Krüger.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
HAVE A QUESTION?
 | 
					 | 
				
			||||||
=====================
 | 
					 | 
				
			||||||
Please post your questions here :
 | 
					 | 
				
			||||||
http://forum.arduino.cc/index.php?topic=266132.0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
DOWNLOAD
 | 
					 | 
				
			||||||
=====================
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Download the latest version (version 2) here :
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
https://github.com/thomasfredericks/Bounce2/archive/master.zip
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
DOCUMENTATION
 | 
					 | 
				
			||||||
=====================
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
The latest version (version 2) documentation can be found here : 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
https://github.com/thomasfredericks/Bounce2/wiki
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ABOUT BOUNCE 1 (ORIGINAL VERSION)
 | 
					 | 
				
			||||||
=====================
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
The original version of Bounce (Bounce 1) is included but not supported anymore.
 | 
					 | 
				
			||||||
@ -1,48 +0,0 @@
 | 
				
			|||||||
 | 
					 | 
				
			||||||
/* 
 | 
					 | 
				
			||||||
 DESCRIPTION
 | 
					 | 
				
			||||||
 ====================
 | 
					 | 
				
			||||||
 Simple example of the Bounce library that switches the debug LED when a button is pressed.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
// Include the Bounce2 library found here :
 | 
					 | 
				
			||||||
// https://github.com/thomasfredericks/Bounce2
 | 
					 | 
				
			||||||
#include <Bounce2.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define BUTTON_PIN 2
 | 
					 | 
				
			||||||
#define LED_PIN 13
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Instantiate a Bounce object
 | 
					 | 
				
			||||||
Bounce debouncer = Bounce(); 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void setup() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Setup the button with an internal pull-up :
 | 
					 | 
				
			||||||
  pinMode(BUTTON_PIN,INPUT_PULLUP);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // After setting up the button, setup the Bounce instance :
 | 
					 | 
				
			||||||
  debouncer.attach(BUTTON_PIN);
 | 
					 | 
				
			||||||
  debouncer.interval(5); // interval in ms
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  //Setup the LED :
 | 
					 | 
				
			||||||
  pinMode(LED_PIN,OUTPUT);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void loop() {
 | 
					 | 
				
			||||||
  // Update the Bounce instance :
 | 
					 | 
				
			||||||
  debouncer.update();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Get the updated value :
 | 
					 | 
				
			||||||
  int value = debouncer.read();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Turn on or off the LED as determined by the state :
 | 
					 | 
				
			||||||
  if ( value == LOW ) {
 | 
					 | 
				
			||||||
    digitalWrite(LED_PIN, HIGH );
 | 
					 | 
				
			||||||
  } 
 | 
					 | 
				
			||||||
  else {
 | 
					 | 
				
			||||||
    digitalWrite(LED_PIN, LOW );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,64 +0,0 @@
 | 
				
			|||||||
 | 
					 | 
				
			||||||
/* 
 | 
					 | 
				
			||||||
 DESCRIPTION
 | 
					 | 
				
			||||||
 ====================
 | 
					 | 
				
			||||||
 Simple example of the Bounce library that switches the debug LED when 
 | 
					 | 
				
			||||||
 either of 2 buttons are pressed.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
// Include the Bounce2 library found here :
 | 
					 | 
				
			||||||
// https://github.com/thomasfredericks/Bounce2
 | 
					 | 
				
			||||||
#include <Bounce2.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define BUTTON_PIN_1 2
 | 
					 | 
				
			||||||
#define BUTTON_PIN_2 3
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define LED_PIN 13
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Instantiate a Bounce object
 | 
					 | 
				
			||||||
Bounce debouncer1 = Bounce(); 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Instantiate another Bounce object
 | 
					 | 
				
			||||||
Bounce debouncer2 = Bounce(); 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void setup() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Setup the first button with an internal pull-up :
 | 
					 | 
				
			||||||
  pinMode(BUTTON_PIN_1,INPUT_PULLUP);
 | 
					 | 
				
			||||||
  // After setting up the button, setup the Bounce instance :
 | 
					 | 
				
			||||||
  debouncer1.attach(BUTTON_PIN_1);
 | 
					 | 
				
			||||||
  debouncer1.interval(5); // interval in ms
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
   // Setup the second button with an internal pull-up :
 | 
					 | 
				
			||||||
  pinMode(BUTTON_PIN_2,INPUT_PULLUP);
 | 
					 | 
				
			||||||
  // After setting up the button, setup the Bounce instance :
 | 
					 | 
				
			||||||
  debouncer2.attach(BUTTON_PIN_2);
 | 
					 | 
				
			||||||
  debouncer2.interval(5); // interval in ms
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  //Setup the LED :
 | 
					 | 
				
			||||||
  pinMode(LED_PIN,OUTPUT);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void loop() {
 | 
					 | 
				
			||||||
  // Update the Bounce instances :
 | 
					 | 
				
			||||||
  debouncer1.update();
 | 
					 | 
				
			||||||
  debouncer2.update();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Get the updated value :
 | 
					 | 
				
			||||||
  int value1 = debouncer1.read();
 | 
					 | 
				
			||||||
  int value2 = debouncer2.read();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Turn on the LED if either button is pressed :
 | 
					 | 
				
			||||||
  if ( value1 == LOW || value2 == LOW ) {
 | 
					 | 
				
			||||||
    digitalWrite(LED_PIN, HIGH );
 | 
					 | 
				
			||||||
  } 
 | 
					 | 
				
			||||||
  else {
 | 
					 | 
				
			||||||
    digitalWrite(LED_PIN, LOW );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,56 +0,0 @@
 | 
				
			|||||||
// Detect the falling edge of multiple buttons.
 | 
					 | 
				
			||||||
// Eight buttons with internal pullups.
 | 
					 | 
				
			||||||
// Toggles a LED when any button is pressed.
 | 
					 | 
				
			||||||
// Buttons on pins 2,3,4,5,6,7,8,9
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Include the Bounce2 library found here :
 | 
					 | 
				
			||||||
// https://github.com/thomasfredericks/Bounce2
 | 
					 | 
				
			||||||
#include <Bounce2.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define LED_PIN 13
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define NUM_BUTTONS 8
 | 
					 | 
				
			||||||
const uint8_t BUTTON_PINS[NUM_BUTTONS] = {2, 3, 4, 5, 6, 7, 8, 9};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int ledState = LOW;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Bounce * buttons = new Bounce[NUM_BUTTONS];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void setup() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  for (int i = 0; i < NUM_BUTTONS; i++) {
 | 
					 | 
				
			||||||
    buttons[i].attach( BUTTON_PINS[i] , INPUT_PULLUP  );       //setup the bounce instance for the current button
 | 
					 | 
				
			||||||
    buttons[i].interval(25);              // interval in ms
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Setup the LED :
 | 
					 | 
				
			||||||
  pinMode(LED_PIN, OUTPUT);
 | 
					 | 
				
			||||||
  digitalWrite(LED_PIN, ledState);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void loop() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  bool needToToggleLed = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  for (int i = 0; i < NUM_BUTTONS; i++)  {
 | 
					 | 
				
			||||||
    // Update the Bounce instance :
 | 
					 | 
				
			||||||
    buttons[i].update();
 | 
					 | 
				
			||||||
    // If it fell, flag the need to toggle the LED
 | 
					 | 
				
			||||||
    if ( buttons[i].fell() ) {
 | 
					 | 
				
			||||||
      needToToggleLed = true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // if a LED toggle has been flagged :
 | 
					 | 
				
			||||||
  if ( needToToggleLed ) {
 | 
					 | 
				
			||||||
    // Toggle LED state :
 | 
					 | 
				
			||||||
    ledState = !ledState;
 | 
					 | 
				
			||||||
    digitalWrite(LED_PIN, ledState);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,48 +0,0 @@
 | 
				
			|||||||
 | 
					 | 
				
			||||||
// Detect the falling edge
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Include the Bounce2 library found here :
 | 
					 | 
				
			||||||
// https://github.com/thomasfredericks/Bounce2
 | 
					 | 
				
			||||||
#include <Bounce2.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define BUTTON_PIN 2
 | 
					 | 
				
			||||||
#define LED_PIN 13
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int ledState = LOW;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Instantiate a Bounce object :
 | 
					 | 
				
			||||||
Bounce debouncer = Bounce(); 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void setup() {
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // Setup the button with an internal pull-up :
 | 
					 | 
				
			||||||
  pinMode(BUTTON_PIN,INPUT_PULLUP);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // After setting up the button, setup the Bounce instance :
 | 
					 | 
				
			||||||
  debouncer.attach(BUTTON_PIN);
 | 
					 | 
				
			||||||
  debouncer.interval(500);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // Setup the LED :
 | 
					 | 
				
			||||||
  pinMode(LED_PIN,OUTPUT);
 | 
					 | 
				
			||||||
  digitalWrite(LED_PIN,ledState);
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void loop() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Update the Bounce instance :
 | 
					 | 
				
			||||||
   debouncer.update();
 | 
					 | 
				
			||||||
   
 | 
					 | 
				
			||||||
   // Call code if Bounce fell (transition from HIGH to LOW) :
 | 
					 | 
				
			||||||
   if ( debouncer.fell() ) {
 | 
					 | 
				
			||||||
      
 | 
					 | 
				
			||||||
     // Toggle LED state :
 | 
					 | 
				
			||||||
     ledState = !ledState;
 | 
					 | 
				
			||||||
     digitalWrite(LED_PIN,ledState);
 | 
					 | 
				
			||||||
     
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 47 KiB  | 
@ -1,53 +0,0 @@
 | 
				
			|||||||
/* 
 | 
					 | 
				
			||||||
DESCRIPTION
 | 
					 | 
				
			||||||
====================
 | 
					 | 
				
			||||||
Reports through serial (57600 baud) the time since 
 | 
					 | 
				
			||||||
a button press (transition from HIGH to LOW).
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Include the Bounce2 library found here :
 | 
					 | 
				
			||||||
// https://github.com/thomasfredericks/Bounce2
 | 
					 | 
				
			||||||
#include <Bounce2.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define BUTTON_PIN 2
 | 
					 | 
				
			||||||
#define LED_PIN 13
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Instantiate a Bounce object :
 | 
					 | 
				
			||||||
Bounce debouncer = Bounce(); 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
unsigned long buttonPressTimeStamp;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void setup() {
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  Serial.begin(57600);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // Setup the button with an internal pull-up :
 | 
					 | 
				
			||||||
  pinMode(BUTTON_PIN,INPUT_PULLUP);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // After setting up the button, setup the Bounce instance :
 | 
					 | 
				
			||||||
  debouncer.attach(BUTTON_PIN);
 | 
					 | 
				
			||||||
  debouncer.interval(5);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // Setup the LED :
 | 
					 | 
				
			||||||
  pinMode(LED_PIN,OUTPUT);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void loop() {
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
   // Update the Bounce instance :
 | 
					 | 
				
			||||||
  debouncer.update();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Call code if Bounce fell (transition from HIGH to LOW) :
 | 
					 | 
				
			||||||
  if ( debouncer.fell()  ) {;
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
    Serial.println( millis()-buttonPressTimeStamp );
 | 
					 | 
				
			||||||
     buttonPressTimeStamp = millis();
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,86 +0,0 @@
 | 
				
			|||||||
 | 
					 | 
				
			||||||
/* 
 | 
					 | 
				
			||||||
DESCRIPTION
 | 
					 | 
				
			||||||
====================
 | 
					 | 
				
			||||||
Example of the bounce library that shows how to retrigger an event when a button is held down.
 | 
					 | 
				
			||||||
In this case, the debug LED will blink every 500 ms as long as the button is held down.
 | 
					 | 
				
			||||||
Open the Serial Monitor (57600 baud) for debug messages.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Include the Bounce2 library found here :
 | 
					 | 
				
			||||||
// https://github.com/thomasfredericks/Bounce2
 | 
					 | 
				
			||||||
#include <Bounce2.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define BUTTON_PIN 2
 | 
					 | 
				
			||||||
#define LED_PIN 13
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Instantiate a Bounce object
 | 
					 | 
				
			||||||
Bounce debouncer = Bounce(); 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int buttonState;
 | 
					 | 
				
			||||||
unsigned long buttonPressTimeStamp;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int ledState;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void setup() {
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  Serial.begin(57600);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // Setup the button
 | 
					 | 
				
			||||||
  pinMode(BUTTON_PIN,INPUT);
 | 
					 | 
				
			||||||
  // Activate internal pull-up
 | 
					 | 
				
			||||||
  digitalWrite(BUTTON_PIN,HIGH);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  // After setting up the button, setup debouncer
 | 
					 | 
				
			||||||
  debouncer.attach(BUTTON_PIN);
 | 
					 | 
				
			||||||
  debouncer.interval(5);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  //Setup the LED
 | 
					 | 
				
			||||||
  pinMode(LED_PIN,OUTPUT);
 | 
					 | 
				
			||||||
  digitalWrite(LED_PIN,ledState);
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void loop() {
 | 
					 | 
				
			||||||
 // Update the debouncer and get the changed state
 | 
					 | 
				
			||||||
  boolean changed = debouncer.update();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  if ( changed ) {
 | 
					 | 
				
			||||||
       // Get the update value
 | 
					 | 
				
			||||||
     int value = debouncer.read();
 | 
					 | 
				
			||||||
    if ( value == HIGH) {
 | 
					 | 
				
			||||||
       ledState = LOW;
 | 
					 | 
				
			||||||
       digitalWrite(LED_PIN, ledState );
 | 
					 | 
				
			||||||
   
 | 
					 | 
				
			||||||
       buttonState = 0;
 | 
					 | 
				
			||||||
       Serial.println("Button released (state 0)");
 | 
					 | 
				
			||||||
   
 | 
					 | 
				
			||||||
   } else {
 | 
					 | 
				
			||||||
          ledState = HIGH;
 | 
					 | 
				
			||||||
       digitalWrite(LED_PIN, ledState );
 | 
					 | 
				
			||||||
       
 | 
					 | 
				
			||||||
         buttonState = 1;
 | 
					 | 
				
			||||||
         Serial.println("Button pressed (state 1)");
 | 
					 | 
				
			||||||
         buttonPressTimeStamp = millis();
 | 
					 | 
				
			||||||
     
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  if  ( buttonState == 1 ) {
 | 
					 | 
				
			||||||
    if ( millis() - buttonPressTimeStamp >= 500 ) {
 | 
					 | 
				
			||||||
         buttonPressTimeStamp = millis();
 | 
					 | 
				
			||||||
         if ( ledState == HIGH ) ledState = LOW;
 | 
					 | 
				
			||||||
         else if ( ledState == LOW ) ledState = HIGH;
 | 
					 | 
				
			||||||
         digitalWrite(LED_PIN, ledState );
 | 
					 | 
				
			||||||
        Serial.println("Retriggering button");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,29 +0,0 @@
 | 
				
			|||||||
#######################################
 | 
					 | 
				
			||||||
# Syntax Coloring Map For Bounce2
 | 
					 | 
				
			||||||
#######################################
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#######################################
 | 
					 | 
				
			||||||
# Datatypes (KEYWORD1)
 | 
					 | 
				
			||||||
#######################################
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Bounce	 KEYWORD1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#######################################
 | 
					 | 
				
			||||||
# Methods and Functions (KEYWORD2)
 | 
					 | 
				
			||||||
#######################################
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
update	 KEYWORD2
 | 
					 | 
				
			||||||
interval	 KEYWORD2
 | 
					 | 
				
			||||||
read	 KEYWORD2
 | 
					 | 
				
			||||||
attach	 KEYWORD2
 | 
					 | 
				
			||||||
rose	KEYWORD2
 | 
					 | 
				
			||||||
fell	KEYWORD2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#######################################
 | 
					 | 
				
			||||||
# Instances (KEYWORD2)
 | 
					 | 
				
			||||||
#######################################
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#######################################
 | 
					 | 
				
			||||||
# Constants (LITERAL1)
 | 
					 | 
				
			||||||
#######################################
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@ -1,16 +0,0 @@
 | 
				
			|||||||
{
 | 
					 | 
				
			||||||
  "name": "Bounce2",
 | 
					 | 
				
			||||||
  "keywords": "bounce, signal, input, ouput",
 | 
					 | 
				
			||||||
  "description": "Debouncing library for Arduino or Wiring",
 | 
					 | 
				
			||||||
  "repository": {
 | 
					 | 
				
			||||||
    "type": "git",
 | 
					 | 
				
			||||||
    "url": "https://github.com/thomasfredericks/Bounce2.git"
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  "version": "2.41",
 | 
					 | 
				
			||||||
  "exclude": [
 | 
					 | 
				
			||||||
    "*.png",
 | 
					 | 
				
			||||||
    "*.zip"
 | 
					 | 
				
			||||||
  ],
 | 
					 | 
				
			||||||
  "frameworks": "arduino",
 | 
					 | 
				
			||||||
  "platforms": "*"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,9 +0,0 @@
 | 
				
			|||||||
name=Bounce2
 | 
					 | 
				
			||||||
version=2.41
 | 
					 | 
				
			||||||
author=Thomas O Fredericks <tof@t-o-f.info> with contributions fromEric Lowry, Jim Schimpf and Tom Harkaway
 | 
					 | 
				
			||||||
maintainer=Thomas O Fredericks <tof@t-o-f.info>
 | 
					 | 
				
			||||||
sentence=Debouncing library for Arduino and Wiring.
 | 
					 | 
				
			||||||
paragraph=Deboucing switches and toggles is important.
 | 
					 | 
				
			||||||
category=Signal Input/Output
 | 
					 | 
				
			||||||
url=https://github.com/thomasfredericks/Bounce2
 | 
					 | 
				
			||||||
architectures=*
 | 
					 | 
				
			||||||
@ -1,7 +1,8 @@
 | 
				
			|||||||
#include "Arduino.h"
 | 
					 | 
				
			||||||
#include "FT18_STW_INIT.h"
 | 
					#include "FT18_STW_INIT.h"
 | 
				
			||||||
#include "Bounce2.h"
 | 
					
 | 
				
			||||||
#include "RotaryEncoder.h"
 | 
					#include <Arduino.h>
 | 
				
			||||||
 | 
					#include <Bounce2.h>
 | 
				
			||||||
 | 
					#include <RotaryEncoder.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
volatile stw_data_type Stw_data = {0}; //alles mit 0 initialisieren
 | 
					volatile stw_data_type Stw_data = {0}; //alles mit 0 initialisieren
 | 
				
			||||||
volatile vehicle_data_type Vehicle_data = {0}; //alles mit 0 initialisieren
 | 
					volatile vehicle_data_type Vehicle_data = {0}; //alles mit 0 initialisieren
 | 
				
			||||||
@ -9,7 +10,8 @@ bool enc1PinALast,enc1PinANow,enc2PinALast,enc2PinANow;
 | 
				
			|||||||
int led[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16};
 | 
					int led[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16};
 | 
				
			||||||
bool entprell;
 | 
					bool entprell;
 | 
				
			||||||
int buttons[] = {button1,button2,button3,button4,button5,button6,enc1PinS,enc2PinS};
 | 
					int buttons[] = {button1,button2,button3,button4,button5,button6,enc1PinS,enc2PinS};
 | 
				
			||||||
Bounce debouncer[8];
 | 
					constexpr size_t N_BUTTONS = sizeof(buttons)/sizeof(buttons[0]);
 | 
				
			||||||
 | 
					Bounce2::Button debouncer[N_BUTTONS];
 | 
				
			||||||
double val = 0;
 | 
					double val = 0;
 | 
				
			||||||
double val2 = 0;
 | 
					double val2 = 0;
 | 
				
			||||||
RotaryEncoder encoder(enc1PinA,enc1PinB,1,1,50);
 | 
					RotaryEncoder encoder(enc1PinA,enc1PinB,1,1,50);
 | 
				
			||||||
@ -23,109 +25,40 @@ void set_pins(){
 | 
				
			|||||||
	for (int thisLed = 0; thisLed < sizeof(led)/sizeof(int); thisLed++) {
 | 
						for (int thisLed = 0; thisLed < sizeof(led)/sizeof(int); thisLed++) {
 | 
				
			||||||
		pinMode(led[thisLed], OUTPUT);
 | 
							pinMode(led[thisLed], OUTPUT);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	/*pinMode(button1, INPUT);
 | 
					 | 
				
			||||||
	pinMode(button2, INPUT);
 | 
					 | 
				
			||||||
	pinMode(button3, INPUT);
 | 
					 | 
				
			||||||
	pinMode(button4, INPUT);
 | 
					 | 
				
			||||||
	pinMode(button5, INPUT);
 | 
					 | 
				
			||||||
	pinMode(button6, INPUT);*/
 | 
					 | 
				
			||||||
	pinMode(enc1PinA, INPUT);
 | 
						pinMode(enc1PinA, INPUT);
 | 
				
			||||||
	pinMode(enc1PinB, INPUT);
 | 
						pinMode(enc1PinB, INPUT);
 | 
				
			||||||
	//pinMode(enc1PinS, INPUT);
 | 
					 | 
				
			||||||
	pinMode(enc2PinA, INPUT);
 | 
						pinMode(enc2PinA, INPUT);
 | 
				
			||||||
	pinMode(enc2PinB, INPUT);
 | 
						pinMode(enc2PinB, INPUT);
 | 
				
			||||||
	//pinMode(enc2PinS, INPUT);
 | 
					 | 
				
			||||||
	//Stw_data.i=0;
 | 
					 | 
				
			||||||
	enc1PinALast=LOW;
 | 
						enc1PinALast=LOW;
 | 
				
			||||||
	enc1PinANow=LOW;
 | 
						enc1PinANow=LOW;
 | 
				
			||||||
	enc2PinALast=LOW;
 | 
						enc2PinALast=LOW;
 | 
				
			||||||
	enc2PinANow=LOW;
 | 
						enc2PinANow=LOW;
 | 
				
			||||||
	for(int i = 0; i < 8; i++){
 | 
						for(int i = 0; i < N_BUTTONS; i++){
 | 
				
			||||||
		pinMode(buttons[i], INPUT);
 | 
							debouncer[i].attach(buttons[i], INPUT);
 | 
				
			||||||
		debouncer[i].attach(buttons[i]);
 | 
					 | 
				
			||||||
		debouncer[i].interval(10);
 | 
							debouncer[i].interval(10);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}	
 | 
					}	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void read_buttons(){
 | 
					void read_buttons(){
 | 
				
			||||||
	/*entprell = digitalRead(button3);
 | 
						for (int i = 0; i < N_BUTTONS; i++) {
 | 
				
			||||||
	delay(10);
 | 
							debouncer[i].update();
 | 
				
			||||||
	if(digitalRead(button3)){
 | 
					 | 
				
			||||||
		Stw_data.Stw_auto_shift = entprell;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	entprell = digitalRead(button2);
 | 
					
 | 
				
			||||||
	delay(10);
 | 
						// These are only used to send them out via CAN, so they only need to be
 | 
				
			||||||
	if(digitalRead(button2)){
 | 
						// high once.
 | 
				
			||||||
		Stw_data.Stw_neutral = entprell;
 | 
						Stw_data.Stw_neutral = debouncer[1].rose();
 | 
				
			||||||
	}
 | 
						Stw_data.Stw_auto_shift = debouncer[2].rose();
 | 
				
			||||||
	entprell = digitalRead(button1);
 | 
						Stw_data.Stw_shift_down = debouncer[4].rose();
 | 
				
			||||||
	delay(10);
 | 
						Stw_data.Stw_shift_up	= debouncer[5].rose();
 | 
				
			||||||
	if(digitalRead(button1)){
 | 
					
 | 
				
			||||||
		Stw_data.buttonState1 = entprell;
 | 
						// These are also used for GUI, so if we set them only at rising edge, they
 | 
				
			||||||
	}
 | 
						// might never be high when checked in the GUI.
 | 
				
			||||||
	entprell = digitalRead(button6);
 | 
						// TODO: Rewrite so we can use debounced values here as well
 | 
				
			||||||
	delay(10);
 | 
					 | 
				
			||||||
	if(digitalRead(button6)){
 | 
					 | 
				
			||||||
		Stw_data.Stw_shift_up = entprell;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	entprell = digitalRead(button5);
 | 
					 | 
				
			||||||
	delay(10);
 | 
					 | 
				
			||||||
	if(digitalRead(button5)){
 | 
					 | 
				
			||||||
		Stw_data.Stw_shift_down = entprell;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	entprell = digitalRead(button4);
 | 
					 | 
				
			||||||
	delay(10);
 | 
					 | 
				
			||||||
	if(digitalRead(button4)){
 | 
					 | 
				
			||||||
		Stw_data.buttonState4 = entprell;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	entprell = digitalRead(enc1PinS);
 | 
					 | 
				
			||||||
	delay(10);
 | 
					 | 
				
			||||||
	if(digitalRead(enc1PinS)){
 | 
					 | 
				
			||||||
		Stw_data.buttonStateEnc1 = entprell;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	entprell = digitalRead(enc2PinS);
 | 
					 | 
				
			||||||
	delay(10);
 | 
					 | 
				
			||||||
	if(digitalRead(enc2PinS)){
 | 
					 | 
				
			||||||
		Stw_data.buttonStateEnc2 = entprell;
 | 
					 | 
				
			||||||
	}*/
 | 
					 | 
				
			||||||
	Stw_data.Stw_auto_shift = digitalRead(button3);
 | 
					 | 
				
			||||||
	Stw_data.Stw_neutral = digitalRead(button2);
 | 
					 | 
				
			||||||
	Stw_data.buttonState1 = digitalRead(button1);
 | 
						Stw_data.buttonState1 = digitalRead(button1);
 | 
				
			||||||
	Stw_data.Stw_shift_up	= digitalRead(button6);
 | 
					 | 
				
			||||||
	Stw_data.Stw_shift_down = digitalRead(button5);
 | 
					 | 
				
			||||||
	Stw_data.buttonState4 = digitalRead(button4);
 | 
						Stw_data.buttonState4 = digitalRead(button4);
 | 
				
			||||||
	Stw_data.buttonStateEnc1 = digitalRead(enc1PinS);
 | 
						Stw_data.buttonStateEnc1 = digitalRead(enc1PinS);
 | 
				
			||||||
	Stw_data.buttonStateEnc2 = digitalRead(enc2PinS);
 | 
						Stw_data.buttonStateEnc2 = digitalRead(enc2PinS);
 | 
				
			||||||
	
 | 
					}
 | 
				
			||||||
	/*for(int i = 0;i < 8; i++){
 | 
					 | 
				
			||||||
		debouncer[i].update();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	debouncer[2].update();
 | 
					 | 
				
			||||||
	if(debouncer[2].fell()){
 | 
					 | 
				
			||||||
		Stw_data.Stw_auto_shift = HIGH;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if(debouncer[1].fell()){
 | 
					 | 
				
			||||||
		Stw_data.Stw_neutral = digitalRead(button2);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if(debouncer[0].fell()){
 | 
					 | 
				
			||||||
		Stw_data.buttonState1 = digitalRead(button1);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if(debouncer[5].fell()){
 | 
					 | 
				
			||||||
		Stw_data.Stw_shift_up	= digitalRead(button6);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if(debouncer[4].fell()){
 | 
					 | 
				
			||||||
		Stw_data.Stw_shift_down = digitalRead(button5);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if(debouncer[3].fell()){
 | 
					 | 
				
			||||||
		Stw_data.buttonState4 = digitalRead(button4);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if(debouncer[6].fell()){
 | 
					 | 
				
			||||||
		Stw_data.buttonStateEnc1 = digitalRead(enc1PinS);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if(debouncer[7].fell()){
 | 
					 | 
				
			||||||
		Stw_data.buttonStateEnc2 = digitalRead(enc2PinS);
 | 
					 | 
				
			||||||
	}*/
 | 
					 | 
				
			||||||
 }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void read_rotary(){
 | 
					void read_rotary(){
 | 
				
			||||||
	int enc = encoder.readEncoder();
 | 
						int enc = encoder.readEncoder();
 | 
				
			||||||
 | 
				
			|||||||
@ -12,7 +12,9 @@
 | 
				
			|||||||
platform = atmelsam
 | 
					platform = atmelsam
 | 
				
			||||||
board = due
 | 
					board = due
 | 
				
			||||||
framework = arduino
 | 
					framework = arduino
 | 
				
			||||||
lib_deps = sebnil/DueFlashStorage@^1.0.0
 | 
					lib_deps =
 | 
				
			||||||
 | 
					    sebnil/DueFlashStorage@^1.0.0
 | 
				
			||||||
 | 
					    thomasfredericks/Bounce2@^2.60
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[env:combustion]
 | 
					[env:combustion]
 | 
				
			||||||
src_filter = +<*> -<18estw.cpp>
 | 
					src_filter = +<*> -<18estw.cpp>
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,4 @@
 | 
				
			|||||||
#include <Arduino.h>
 | 
					#include <Arduino.h>
 | 
				
			||||||
#include <Bounce2.h>
 | 
					 | 
				
			||||||
#include <DueTimer.h>
 | 
					#include <DueTimer.h>
 | 
				
			||||||
#include <EDIPTFT.h>
 | 
					#include <EDIPTFT.h>
 | 
				
			||||||
#include <FT18_STW_DISPLAY.h>
 | 
					#include <FT18_STW_DISPLAY.h>
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user