Permalink
Browse files

Experimental is working again!

  • Loading branch information...
stevecooley committed Sep 6, 2013
1 parent ebf4daa commit a9f478bca5cf5d79f2d61da01393d8cec5a95cae
Showing with 3,090 additions and 0 deletions.
  1. +150 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/ClickButton.cpp
  2. +36 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/ClickButton.h
  3. +151 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/LED.cpp
  4. +52 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/LED.h
  5. +60 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/PString.cpp
  6. +87 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/PString.h
  7. +95 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/Potentiometer.cpp
  8. +41 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/Potentiometer.h
  9. +129 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/beatseqr_arduino_firmware_4_experimental.ino
  10. +369 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/config.h
  11. +1 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/eeprom.ino
  12. +426 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/knob_routine.ino
  13. +326 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/pattern_select_routine.ino
  14. +115 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/serial_utilities.ino
  15. +178 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/step_button_routine.ino
  16. +133 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/transport_button_routine.ino
  17. +317 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/voice_select_button_routine.ino
  18. +424 −0 arduino_code/beatseqr_arduino_firmware_4_experimental/voice_slider_routine.ino
@@ -0,0 +1,150 @@
+/* ClickButton
+
+ Arduino library that decodes multiple clicks on one button.
+ Also copes with long clicks and click-and-hold.
+
+ Usage: ClickButton buttonObject(pin [LOW/HIGH, [CLICKBTN_PULLUP]]);
+
+ where LOW/HIGH denotes active LOW or HIGH button (default is LOW)
+ CLICKBTN_PULLUP is only possible with active low buttons.
+
+
+ Returned click counts:
+
+ A positive number denotes the number of (short) clicks after a released button
+ A negative number denotes the number of "long" clicks
+
+NOTE!
+ This is the OPPOSITE/negative of click codes from the last pre-2013 versions!
+ (this seemed more logical and simpler, so I finally changed it)
+
+ Based on the Debounce example at arduino playground site
+
+
+ Copyright (C) 2010,2012, 2013 raron
+
+
+ GNU GPLv3 license
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+
+
+
+ Contact: raronzen@gmail.com
+
+
+ History:
+ 2013.08.29 - Some small clean-up of code, more sensible variable names etc.
+ Added another example code for multiple buttons in an object array
+ 2013.04.23 - A "minor" debugging: active-high buttons now work (wops)!
+ Thanks goes to John F. H. for pointing that out!
+ 2013.02.17 - Some improvements, simplified click codes.
+ Added a LED fader example. Thanks to Tom K. for the idea.
+ 2012.01.31 - Tiny update for Arduino 1.0
+ 2010.06.15 - First version. Basically just a small OOP programming exercise.
+*/
+
+#include "ClickButton.h"
+
+ClickButton::ClickButton(uint8_t buttonPin)
+{
+ _pin = buttonPin;
+ _activeHigh = LOW; // Assume active-low button
+ _btnState = !_activeHigh; // initial button state in active-high logic
+ _lastState = _btnState;
+ _clickCount = 0;
+ clicks = 0;
+ depressed = false;
+ _lastBounceTime= 0;
+ debounceTime = 20; // Debounce timer in ms
+ multiclickTime = 50; // Time limit for multi clicks
+ longClickTime = 1000; // time until long clicks register
+ pinMode(_pin, INPUT);
+}
+
+
+ClickButton::ClickButton(uint8_t buttonPin, boolean activeType)
+{
+ _pin = buttonPin;
+ _activeHigh = activeType;
+ _btnState = !_activeHigh; // initial button state in active-high logic
+ _lastState = _btnState;
+ _clickCount = 0;
+ clicks = 0;
+ depressed = 0;
+ _lastBounceTime= 0;
+ debounceTime = 20; // Debounce timer in ms
+ multiclickTime = 50; // Time limit for multi clicks
+ longClickTime = 1000; // time until long clicks register
+ pinMode(_pin, INPUT);
+}
+
+ClickButton::ClickButton(uint8_t buttonPin, boolean activeType, boolean internalPullup)
+{
+ _pin = buttonPin;
+ _activeHigh = activeType;
+ _btnState = !_activeHigh; // initial button state in active-high logic
+ _lastState = _btnState;
+ _clickCount = 0;
+ clicks = 0;
+ depressed = 0;
+ _lastBounceTime= 0;
+ debounceTime = 20; // Debounce timer in ms
+ multiclickTime = 50; // Time limit for multi clicks
+ longClickTime = 1000; // time until "long" click register
+ pinMode(_pin, INPUT);
+ // Turn on internal pullup resistor if applicable
+ if (_activeHigh == LOW && internalPullup == CLICKBTN_PULLUP) digitalWrite(_pin,HIGH);
+}
+
+
+
+void ClickButton::Update()
+{
+ long now = (long)millis(); // get current time
+ _btnState = digitalRead(_pin); // current appearant button state
+
+ // Make the button logic active-high in code
+ if (!_activeHigh) _btnState = !_btnState;
+
+ // If the switch changed, due to noise or a button press, reset the debounce timer
+ if (_btnState != _lastState) _lastBounceTime = now;
+
+
+ // debounce the button (Check if a stable, changed state has occured)
+ if (now - _lastBounceTime > debounceTime && _btnState != depressed)
+ {
+ depressed = _btnState;
+ if (depressed) _clickCount++;
+ }
+
+ // If the button released state is stable, report nr of clicks and start new cycle
+ if (!depressed && (now - _lastBounceTime) > multiclickTime)
+ {
+ // positive count for released buttons
+ clicks = _clickCount;
+ _clickCount = 0;
+ }
+
+ // Check for "long click"
+ if (depressed && (now - _lastBounceTime > longClickTime))
+ {
+ // negative count for long clicks
+ clicks = 0 - _clickCount;
+ _clickCount = 0;
+ }
+
+ _lastState = _btnState;
+}
+
@@ -0,0 +1,36 @@
+#ifndef ClickButton_H
+#define ClickButton_H
+
+#if (ARDUINO < 100)
+#include <WProgram.h>
+#else
+#include <Arduino.h>
+#endif
+
+
+#define CLICKBTN_PULLUP HIGH
+
+
+class ClickButton
+{
+ public:
+ ClickButton(uint8_t buttonPin);
+ ClickButton(uint8_t buttonPin, boolean active);
+ ClickButton(uint8_t buttonPin, boolean active, boolean internalPullup);
+ void Update();
+ int clicks; // button click counts to return
+ boolean depressed; // the currently debounced button (press) state (presumably it is not sad :)
+ long debounceTime;
+ long multiclickTime;
+ long longClickTime;
+ private:
+ uint8_t _pin; // Arduino pin connected to the button
+ boolean _activeHigh; // Type of button: Active-low = 0 or active-high = 1
+ boolean _btnState; // Current appearant button state
+ boolean _lastState; // previous button reading
+ int _clickCount; // Number of button clicks within multiclickTime milliseconds
+ long _lastBounceTime; // the last time the button input pin was toggled, due to noise or a press
+};
+
+#endif
+
@@ -0,0 +1,151 @@
+/* $Id: LED.cpp 1198 2011-06-14 21:08:27Z bhagman $
+||
+|| @author Alexander Brevig <abrevig@wiring.org.co>
+|| @url http://wiring.org.co/
+|| @url http://alexanderbrevig.com/
+|| @contribution Brett Hagman <bhagman@wiring.org.co>
+||
+|| @description
+|| | This is a Hardware Abstraction Library for LEDs.
+|| | Provides an easy way of handling LEDs.
+|| |
+|| | Wiring Cross-platform Library
+|| #
+||
+|| @license Please see cores/Common/License.txt.
+||
+*/
+
+#include "LED.h"
+
+/*
+|| @constructor
+|| | Initialize the LED
+|| | Set the pinMode of the LED
+|| #
+||
+|| @parameter ledPin the pin connected to this LED
+*/
+LED::LED(uint8_t ledPin)
+{
+ pin = ledPin;
+ status = LOW;
+ pinMode(pin, OUTPUT);
+}
+
+/*
+|| @description
+|| | Get the state of this LED
+|| #
+||
+|| @return The state of this LED [ HIGH | LOW ]
+*/
+bool LED::getState()
+{
+ return status;
+}
+
+/*
+|| @description
+|| | Set this LED on
+|| #
+*/
+void LED::on(void)
+{
+ digitalWrite(pin, HIGH);
+ status = true;
+}
+
+/*
+|| @description
+|| | Set this LED off
+|| #
+*/
+void LED::off(void)
+{
+ digitalWrite(pin, LOW);
+ status = false;
+}
+
+/*
+|| @description
+|| | Toggle this LED
+|| | It will change state from on to off, or off to on
+|| #
+*/
+void LED::toggle(void)
+{
+ status ? off() : on();
+}
+
+/*
+|| @description
+|| | Bling this led a number of times, with the duration of time each blink
+|| #
+||
+|| @parameter time the time each blink will take
+|| @parameter times the number of blinks
+*/
+void LED::blink(unsigned int time, byte times)
+{
+ for (byte i = 0; i < times; i++)
+ {
+ toggle();
+ delay(time / 2);
+ toggle();
+ delay(time / 2);
+ }
+}
+
+/*
+|| @description
+|| | This method assumes a PWM pin
+|| | analogWrites the pin if PWM, else it either turn it on or off
+|| #
+||
+|| @parameter val the value to set the LED to [0,255]
+*/
+void LED::setValue(byte val)
+{
+ analogWrite(pin, val);
+ status = (val <= 127) ? false : true;
+}
+
+/*
+|| @description
+|| | This method assumes a PWM pin
+|| | It will fade the LED from off to on
+|| | analogWrites the pin if PWM, else it ends up turning this LED on
+|| #
+||
+|| @parameter time the time that the fade will last
+*/
+void LED::fadeIn(unsigned int time)
+{
+ for (byte value = 0 ; value < 255; value += 5)
+ {
+ analogWrite(pin, value);
+ delay(time / (255 / 5));
+ }
+ on();
+}
+
+/*
+|| @description
+|| | This method assumes a PWM pin
+|| | It will fade the LED from on to off
+|| | analogWrites the pin if PWM, else it ends up turning this LED on
+|| #
+||
+|| @parameter time the time that the fade will last
+*/
+void LED::fadeOut(unsigned int time)
+{
+ for (byte value = 255; value > 0; value -= 5)
+ {
+ analogWrite(pin, value);
+ delay(time / (255 / 5));
+ }
+ off();
+}
+
@@ -0,0 +1,52 @@
+/*
+||
+ || @file LED.h
+ || @version 1.1
+ || @author Alexander Brevig
+ || @contact alexanderbrevig@gmail.com
+ ||
+ || @description
+ || | Provide an easy way of making/using LEDs
+ || #
+ ||
+ || @license
+ || | Copyright (c) 2009 Alexander Brevig. All rights reserved.
+ || | This code is subject to AlphaLicence.txt
+ || | alphabeta.alexanderbrevig.com/AlphaLicense.txt
+ || #
+ ||
+ */
+
+#ifndef LED_H
+#define LED_H
+
+#include "Arduino.h"
+
+class LED{
+public:
+ LED(uint8_t ledPin);
+ bool getState();
+ void on();
+ void off();
+ void toggle();
+ void blink(unsigned int time, byte times=1);
+ void setValue(byte val);
+ void fadeIn(unsigned int time);
+ void fadeOut(unsigned int time);
+private:
+ bool status;
+ uint8_t pin;
+};
+
+extern LED DEBUG_LED;
+
+#endif
+
+/*
+|| @changelog
+ || | 1.1 2009-05-07 - Alexander Brevig : Added blink(uint,byte), requested by: Josiah Ritchie - josiah@josiahritchie.com
+ || | 1.1 2009-04-07 - Alexander Brevig : Altered API
+ || | 1.0 2009-04-17 - Alexander Brevig : Initial Release
+ || #
+ */
+
Oops, something went wrong.

0 comments on commit a9f478b

Please sign in to comment.