Skip to content

Instantly share code, notes, and snippets.

@Technicus
Last active February 13, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Technicus/78048f874272294af14b to your computer and use it in GitHub Desktop.
Save Technicus/78048f874272294af14b to your computer and use it in GitHub Desktop.
Referencing a different object from an object, line 37 of Bounce2.h with line 62 of Development_0.ino
// Please read Bounce2.h for information about the liscence and authors
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "Bounce2.h"
#include "Development_0.h"
#define DEBOUNCED_STATE 0
#define UNSTABLE_STATE 1
#define STATE_CHANGED 3
Bounce::Bounce()
: previous_millis(0)
, interval_millis(10)
, state(0)
, pin(0)
{}
void Bounce::attach(int pin) {
this->pin = pin;
//bool read = digitalRead(pin);
bool read = musicPlayer.GPIO_digitalRead(pin);
state = 0;
if (digitalRead(pin)) {
state = _BV(DEBOUNCED_STATE) | _BV(UNSTABLE_STATE);
}
#ifdef BOUNCE_LOCK_OUT
previous_millis = 0;
#else
previous_millis = millis();
#endif
}
void Bounce::attach(int pin, int mode){
//pinMode(pin, mode);
musicPlayer.GPIO_pinMode(pin, mode);
this->attach(pin);
}
void Bounce::interval(uint16_t interval_millis)
{
this->interval_millis = interval_millis;
}
bool Bounce::update()
{
#ifdef BOUNCE_LOCK_OUT
state &= ~_BV(STATE_CHANGED);
// Ignore everything if we are locked out
if (millis() - previous_millis >= interval_millis) {
//bool currentState = digitalRead(pin);
bool currentState = musicPlayer.GPIO_digitalRead(pin);
if ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
previous_millis = millis();
state ^= _BV(DEBOUNCED_STATE);
state |= _BV(STATE_CHANGED);
}
}
return state & _BV(STATE_CHANGED);
#else
// Read the state of the switch in a temporary variable.
// bool currentState = digitalRead(pin);
bool currentState = musicPlayer.GPIO_digitalRead(pin);
state &= ~_BV(STATE_CHANGED);
// If the reading is different from last reading, reset the debounce counter
if ( currentState != (bool)(state & _BV(UNSTABLE_STATE)) ) {
previous_millis = millis();
state ^= _BV(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 ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
previous_millis = millis();
state ^= _BV(DEBOUNCED_STATE);
state |= _BV(STATE_CHANGED);
}
}
return state & _BV(STATE_CHANGED);
#endif
}
bool Bounce::read()
{
return state & _BV(DEBOUNCED_STATE);
}
bool Bounce::rose()
{
return ( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
}
bool Bounce::fell()
{
return !( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
}
/*
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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifdef BOUNCE_LOCK
#error You are using the invalid BOUNCE_LOCK-OUT define. Please update your sources to use BOUNCE_LOCK_OUT
#endif
// Uncomment the following line for "LOCK-OUT" debounce method
//#define BOUNCE_LOCK_OUT
#ifndef Bounce2_h
#define Bounce2_h
#include <inttypes.h>
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();
protected:
unsigned long previous_millis;
uint16_t interval_millis;
uint8_t state;
uint8_t pin;
};
#endif
#include <Adafruit_VS1053.h>
#include <SPI.h>
#include <Bounce2.h>
#include "Development_0.h"
#define VS1053_RESET A2 // VS1053 reset pin (output)
#define VS1053_CS A1 // VS1053 chip select pin (output)
#define VS1053_DCS A3 // VS1053 Data/command select pin (output)
#define VS1053_CARDCS A4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define VS1053_DREQ 2 // VS1053 Data request, ideally an Interrupt pin
// Create object for VS1053 Codec
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, VS1053_CARDCS);
int volume[] = {20, 20};
#define BUTTON_PIN 0
#define LED_PIN A0
// Instantiate a Bounce object
Bounce debouncer = Bounce();
void setup() {
Serial.begin(9600);
Serial.println("Development - 0");
if (! musicPlayer.begin()) { // initialise the music player
//textBox(0, 1, "Couldn't find VS1053, HALT!", RED);
Serial.println("Couldn't find VS1053, HALT!");
while (1); // don't do anything more
}
//textBox(0, 1, "VS1053 found.", YELLOW);
Serial.println("VS1053 found.");
musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working
delay(500);
if (!SD.begin(VS1053_CARDCS)) {
//textBox(0, 1, "SD failed, or not present, HALT!", RED);
Serial.println("SD failed, or not present, HALT!");
while (1); // don't do anything more
}
//textBox(0, 1, "SD OK.", YELLOW);
delay(500);
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(volume[0], volume[1]);
if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT)){
//textBox(0, 1, "DREQ pin is not an interrupt pin", YELLOW);
Serial.println("DREQ pin is not an interrupt pin");
} else {
//textBox(0, 1, "DREQ pin is an interrupt pin", YELLOW);
Serial.println("DREQ pin is an interrupt pin");
}
delay(500);
// // Setup the buttons with as inputs :
// for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
// musicPlayer.GPIO_pinMode(button[pinSelect], INPUT);
// delay(100);
// }
//
// // After setting up the button, setup the Bounce instance :
// for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
// debouncer[pinSelect].attach(pinSelect);
// debouncer[pinSelect].interval(5); // interval in ms
// }
//textBox(TOP, PRINT, "musicPlayer.GPIO initalized.", YELLOW);
Serial.println("musicPlayer.GPIO initalized.");
delay(500);
// Setup the button as an input :
musicPlayer.GPIO_pinMode(BUTTON_PIN,INPUT);
//pinMode(BUTTON_PIN,INPUT);
// 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);
Serial.println("Now there are bouncers.");
}
void loop() {
// Update the Bounce instance :
debouncer.update();
// Get the updated value :
int value = debouncer.read();
Serial.println(value);
// Turn on or off the LED as determined by the state :
if ( value == LOW ) {
digitalWrite(LED_PIN, HIGH );
}
else {
digitalWrite(LED_PIN, LOW );
}
}
#include <Adafruit_VS1053.h>
#include <SPI.h>
// #include <Bounce2.h>
// #include "Development_0.h"
#define VS1053_RESET A2 // VS1053 reset pin (output)
#define VS1053_CS A1 // VS1053 chip select pin (output)
#define VS1053_DCS A3 // VS1053 Data/command select pin (output)
#define VS1053_CARDCS A4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define VS1053_DREQ 2 // VS1053 Data request, ideally an Interrupt pin
// Create object for VS1053 Codec
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, VS1053_CARDCS);
int volume[] = {20, 20};
#define BUTTON_PIN 0
#define LED_PIN A0
// Variables will change:
int ledState = LOW; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flicke
// Instantiate a Bounce object
// Bounce debouncer = Bounce();
void setup() {
Serial.begin(9600);
Serial.println("");
Serial.println("Development - 0");
if (! musicPlayer.begin()) { // initialise the music player
//textBox(0, 1, "Couldn't find VS1053, HALT!", RED);
Serial.println("Couldn't find VS1053, HALT!");
while (1); // don't do anything more
}
//textBox(0, 1, "VS1053 found.", YELLOW);
Serial.println("VS1053 found.");
musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working
delay(500);
if (!SD.begin(VS1053_CARDCS)) {
//textBox(0, 1, "SD failed, or not present, HALT!", RED);
Serial.println("SD failed, or not present, HALT!");
while (1); // don't do anything more
}
//textBox(0, 1, "SD OK.", YELLOW);
delay(500);
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(volume[0], volume[1]);
if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT)){
//textBox(0, 1, "DREQ pin is not an interrupt pin", YELLOW);
Serial.println("DREQ pin is not an interrupt pin");
} else {
//textBox(0, 1, "DREQ pin is an interrupt pin", YELLOW);
Serial.println("DREQ pin is an interrupt pin");
}
delay(500);
// // Setup the buttons with as inputs :
// for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
// musicPlayer.GPIO_pinMode(button[pinSelect], INPUT);
// delay(100);
// }
//
// // After setting up the button, setup the Bounce instance :
// for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
// debouncer[pinSelect].attach(pinSelect);
// debouncer[pinSelect].interval(5); // interval in ms
// }
//textBox(TOP, PRINT, "musicPlayer.GPIO initalized.", YELLOW);
// Setup the button as an input :
// musicPlayer.GPIO_pinMode(BUTTON_PIN,INPUT);
musicPlayer.GPIO_pinMode(BUTTON_PIN, INPUT);
Serial.println("musicPlayer.GPIO initalized.");
delay(500);
// After setting up the button, setup the Bounce instance :
// debouncer.attach(BUTTON_PIN, INPUT);
// debouncer.interval(5); // interval in ms
//Setup the LED :
pinMode(LED_PIN,OUTPUT);
Serial.println("Now there are bouncers.");
}
void loop() {
// read the state of the switch into a local variable:
int reading = musicPlayer.GPIO_digitalRead(BUTTON_PIN);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
Serial.println(buttonState);
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
ledState = !ledState;
}
}
}
// set the LED:
digitalWrite(LED_PIN, ledState);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
// // Turn on or off the LED as determined by the state :
// if ( value == LOW ) {
// digitalWrite(LED_PIN, HIGH );
// }
// else {
// digitalWrite(LED_PIN, LOW );
// }
}
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
#include <Adafruit_VS1053.h>
#include <SPI.h>
#include <Bounce2.h>
// #include <Adafruit_VS1053.h>
// #include <SPI.h>
// #include "Arduino.h"
// #include <inttypes.h>
//#include "WProgram.h"
// #include <Bounce2.h>
// #include "Development_0.h"
#define VS1053_RESET A2 // VS1053 reset pin (output)
#define VS1053_CS A1 // VS1053 chip select pin (output)
#define VS1053_DCS A3 // VS1053 Data/command select pin (output)
#define VS1053_CARDCS A4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define VS1053_DREQ 2 // VS1053 Data request, ideally an Interrupt pin
// Create object for VS1053 Codec
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, VS1053_CARDCS);
int volume[] = {20, 20};
#define BUTTON_PIN 0
#define HEART_PIN A0
#define NUMBUTTONS sizeof(button)
// Variables will change:
int ledState = LOW; // the current state of the output pin
// int buttonState; // the current reading from the input pin
// int lastButtonState = LOW; // the previous reading from the input pin
int button[] = { 0, 1, 2, 3, 4, 5, 6, 7};
int buttonState_Reading[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
int buttonState_Current[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
int buttonState_Previous[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime[] = {0, 0, 0, 0, 0, 0, 0, 0}; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flicke
// Instantiate a Bounce object
// Bounce debouncer = Bounce();
int beat = 0;
void setup() {
Serial.begin(9600);
Serial.println("");
Serial.println("Development - 0");
// initialize the LED pin as an output:
pinMode(HEART_PIN, OUTPUT);
//textBox(0, 1, "Heartbeat initalized.", YELLOW);
heartBeat(0);
delay(500);
heartBeat(1);
delay(500);
heartBeat(2);
delay(500);
Serial.println("Heartbeat initalized.");
if (! musicPlayer.begin()) { // initialise the music player
//textBox(0, 1, "Couldn't find VS1053, HALT!", RED);
Serial.println("Couldn't find VS1053, HALT!");
while (1); // don't do anything more
}
//textBox(0, 1, "VS1053 found.", YELLOW);
Serial.println("VS1053 found.");
musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working
delay(500);
if (!SD.begin(VS1053_CARDCS)) {
//textBox(0, 1, "SD failed, or not present, HALT!", RED);
Serial.println("SD failed, or not present, HALT!");
while (1); // don't do anything more
}
//textBox(0, 1, "SD OK.", YELLOW);
delay(500);
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(volume[0], volume[1]);
if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT)){
//textBox(0, 1, "DREQ pin is not an interrupt pin", YELLOW);
Serial.println("DREQ pin is not an interrupt pin");
} else {
//textBox(0, 1, "DREQ pin is an interrupt pin", YELLOW);
Serial.println("DREQ pin is an interrupt pin");
}
delay(500);
// Setup the buttons with as inputs :
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
musicPlayer.GPIO_pinMode(button[pinSelect], INPUT);
delay(100);
}
Serial.println("musicPlayer.GPIO initalized.");
delay(500);
Serial.println(". . . Ready . . .");
}
void loop() {
// read the state of the switch into a local variable:
//int reading = musicPlayer.GPIO_digitalRead(BUTTON_PIN);
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
buttonState_Current[pinSelect] = musicPlayer.GPIO_digitalRead(pinSelect);
delay(100);
}
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
// if (reading != lastButtonState) {
// // reset the debouncing timer
// lastDebounceTime = millis();
// }
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
if (buttonState_Reading[pinSelect] != buttonState_Previous[pinSelect]) {
// reset the debouncing timer
lastDebounceTime[pinSelect] = millis();
}
}
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
if ((millis() - lastDebounceTime[pinSelect]) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (buttonState_Reading[pinSelect] != buttonState_Current[pinSelect]) {
buttonState_Current[pinSelect] = buttonState_Reading[pinSelect];
//Serial.println(buttonState_Current[pinSelect]);
// only toggle the LED if the new button state is HIGH
if (buttonState_Current[pinSelect] == HIGH) {
beat = 2;
}
}
}
}
// set the beat
heartBeat(beat);
if (array_cmp(buttonState_Previous, buttonState_Current, 8, 8) == true){
// do this if they are equal
}else{
// do this if they are different
for (int pinSelect = 0; pinSelect < 8; pinSelect++) {
if (pinSelect == 0){
Serial.print("{");
}
Serial.print(buttonState_Current[pinSelect]);
if (pinSelect == 7){
Serial.println("}");
}
else {
Serial.print(", ");
}
}
}
memcpy( buttonState_Previous, buttonState_Current, 8 );
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
// for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
// ButtonState_Previous[pinSelect] = buttonState_Reading[pinSelect];
// }
}
void heartBeat(int beat) {
switch(beat){
case 0: {
digitalWrite(HEART_PIN, LOW);
break;
}
case 1: {
digitalWrite(HEART_PIN, HIGH);
}
case 2: {
if (digitalRead(HEART_PIN) == LOW){
digitalWrite(HEART_PIN, HIGH);
}
else {
digitalWrite(HEART_PIN, LOW);
}
}
case 3: {
if (digitalRead(HEART_PIN) == LOW){
digitalWrite(HEART_PIN, HIGH);
delay(200);
digitalWrite(HEART_PIN, LOW);
delay(200);
}
else {
digitalWrite(HEART_PIN, LOW);
delay(200);
digitalWrite(HEART_PIN, HIGH);
delay(200);
}
}
}
}
#ifndef DEVELOPMENT_H_INCLUDE
#define DEVELOPMENT_H_INCLUDE
#include <Adafruit_VS1053.h>
extern Adafruit_VS1053_FilePlayer musicPlayer;
#endif
#include <Adafruit_VS1053.h>
#include <SPI.h>
#include <Bounce2.h>
#include "Development_0.h"
#define VS1053_RESET A2 // VS1053 reset pin (output)
#define VS1053_CS A1 // VS1053 chip select pin (output)
#define VS1053_DCS A3 // VS1053 Data/command select pin (output)
#define VS1053_CARDCS A4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define VS1053_DREQ 2 // VS1053 Data request, ideally an Interrupt pin
// Create object for VS1053 Codec
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, VS1053_CARDCS);
int volume[] = {20, 20};
int button[] = { 0, 1, 2, 3, 4, 5, 6, 7};
int buttonState[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
int lastButtonState[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
#define NUMBUTTONS sizeof(button)
// Instantiate a Bounce object
Bounce debouncer[NUMBUTTONS] = {
Bounce(),
Bounce(),
Bounce(),
Bounce(),
Bounce(),
Bounce(),
Bounce(),
Bounce()
};
void setup(void) {
Serial.begin(9600);
Serial.println("Development - 0");
if (! musicPlayer.begin()) { // initialise the music player
//textBox(0, 1, "Couldn't find VS1053, HALT!", RED);
Serial.println("Couldn't find VS1053, HALT!");
while (1); // don't do anything more
}
//textBox(0, 1, "VS1053 found.", YELLOW);
Serial.println("VS1053 found.");
musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working
delay(500);
if (!SD.begin(VS1053_CARDCS)) {
//textBox(0, 1, "SD failed, or not present, HALT!", RED);
Serial.println("SD failed, or not present, HALT!");
while (1); // don't do anything more
}
//textBox(0, 1, "SD OK.", YELLOW);
delay(500);
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(volume[0], volume[1]);
if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT)){
//textBox(0, 1, "DREQ pin is not an interrupt pin", YELLOW);
Serial.println("DREQ pin is not an interrupt pin");
} else {
//textBox(0, 1, "DREQ pin is an interrupt pin", YELLOW);
Serial.println("DREQ pin is an interrupt pin");
}
delay(500);
Serial.println("Now there are bouncers.");
// Setup the buttons with as inputs :
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
musicPlayer.GPIO_pinMode(button[pinSelect], INPUT);
delay(100);
}
// After setting up the button, setup the Bounce instance :
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
debouncer[pinSelect].attach(pinSelect);
debouncer[pinSelect].interval(5); // interval in ms
}
//textBox(TOP, PRINT, "musicPlayer.GPIO initalized.", YELLOW);
delay(500);
}
void loop(){
// Update the Bounce instance :
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
debouncer[pinSelect].update();
}
// Get the updated value :
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
buttonState[pinSelect] = debouncer[pinSelect].read();
}
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
if (pinSelect == 0){
Serial.print("{");
}
Serial.print(buttonState[pinSelect]);
if (pinSelect == 7){
Serial.println("}");
}
else {
Serial.print(", ");
}
}
memcpy(lastButtonState, buttonState, 8);
Serial.println("");
// without dbouncer object
// for (int pinSelect = 0; pinSelect < 8; pinSelect++) {
// buttonState[pinSelect] = musicPlayer.GPIO_digitalRead(pinSelect);
// }
//
// if (array_cmp(lastButtonState, buttonState, 8, 8) == true){
// // do this if they are equal
// }else{
// // do this if they are different
// for (int pinSelect = 0; pinSelect < 8; pinSelect++) {
// if (pinSelect == 0){
// Serial.print("{");
// }
// Serial.print(buttonState[pinSelect]);
// if (pinSelect == 7){
// Serial.println("}");
// }
// else {
// Serial.print(", ");
// }
// }
// }
// memcpy(lastButtonState, buttonState, 8);
}
/*
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 );
}
}
// Detect the falling edge
// Include the Bounce2 library found here :
// https://github.com/thomasfredericks/Bounce-Arduino-Wiring
#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);
}
}
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
#include <Adafruit_VS1053.h>
#include <SPI.h>
#include <Bounce2.h>
#define VERSION "Test_7_TFT_Codec_GPIO"
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Text Boxes
#define TOP 0
#define BOTTOM 1
#define LEFT 2
#define RIGHT 3
#define CENTER 4
#define CLEAR 0
#define PRINT 1
// Media Symbols
#define PLAY 0
#define RECORD 1
#define STOP 2
#define PAUSE 3
#define PREVIOUS 4
#define NEXT 5
#define UP 6
#define DOWN 7
// SPI pins
//#define sclk 13
//#define mosi 11
#define TFT_DC 8
#define TFT_CS 10
#define TFT_RESET 9
#define VS1053_RESET A2 // VS1053 reset pin (output)
#define VS1053_CS A1 // VS1053 chip select pin (output)
#define VS1053_DCS A3 // VS1053 Data/command select pin (output)
#define VS1053_CARDCS A4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define VS1053_DREQ 2 // VS1053 Data request, ideally an Interrupt pin
// Create object for VS1053 Codec
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, VS1053_CARDCS);
// Create object for TFT SSD1351
Adafruit_SSD1351 tft = Adafruit_SSD1351(TFT_CS, TFT_DC, TFT_RESET);
const int heartPin = A0; // the number of the LED pin
int beat = 0;
int volume[] = {20, 20};
// Function Prototypes
void textBox(int box, int action,char *text, uint16_t color);
void heartBeat(int beat);
void mediaButton(int symbol);
void check_switches();
// Image data
const unsigned char mugg_0[] PROGMEM = {
0xff, 0x00, 0x04, 0x92, 0x04, 0x81, 0x00, 0xff, 0xff, 0x4a, 0x98, 0x20, 0x86, 0xf8, 0x10, 0xff,
0xff, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0x48, 0x92, 0x00, 0x00, 0x00, 0x10, 0xff,
0xff, 0x30, 0x24, 0x00, 0x00, 0x80, 0x08, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x08, 0x92, 0xff,
0xff, 0x22, 0x20, 0x00, 0x00, 0x12, 0x09, 0xff, 0xff, 0x09, 0x00, 0x00, 0x00, 0x08, 0x12, 0xff,
0xff, 0x10, 0x00, 0x00, 0x00, 0x00, 0x05, 0xff, 0xff, 0x09, 0x00, 0x00, 0x00, 0x01, 0x02, 0xff,
0xff, 0x12, 0x00, 0x00, 0x00, 0x02, 0x05, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0xff,
0xff, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x01, 0xff, 0xff, 0x00, 0x01, 0x81, 0xf8, 0x01, 0x30, 0xff,
0xff, 0x00, 0x00, 0x43, 0xfc, 0x00, 0x00, 0xff, 0xff, 0x00, 0x01, 0x07, 0xff, 0x00, 0x00, 0xff,
0xff, 0x00, 0x11, 0x07, 0xff, 0x80, 0x40, 0xff, 0xff, 0x00, 0x01, 0x0f, 0xff, 0xc0, 0x04, 0xff,
0xff, 0x00, 0x23, 0x0f, 0xff, 0xe0, 0x50, 0xff, 0xff, 0x00, 0x22, 0x1f, 0xff, 0xa0, 0x24, 0xff,
0xff, 0x80, 0x02, 0x1f, 0xff, 0xa0, 0x08, 0xff, 0xff, 0x00, 0x06, 0x3f, 0xff, 0xa0, 0x04, 0xff,
0xff, 0x80, 0x04, 0x3f, 0xff, 0xa0, 0x08, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xfe, 0xa0, 0x10, 0xff,
0xff, 0x80, 0x00, 0x1f, 0x83, 0x20, 0x09, 0xff, 0xff, 0x00, 0x08, 0x8f, 0xff, 0xf0, 0x06, 0xff,
0xff, 0x00, 0x01, 0x0f, 0xe1, 0xf0, 0x0b, 0xff, 0xff, 0x00, 0x00, 0x4f, 0xc1, 0x30, 0x04, 0xff,
0xff, 0x00, 0x00, 0x3f, 0xd0, 0x30, 0x09, 0xff, 0xff, 0x00, 0x03, 0xff, 0xfb, 0x70, 0x22, 0xff,
0xff, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x00, 0xff,
0xff, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x02, 0xff,
0xff, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x00, 0xff, 0xff, 0x80, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0xff,
0xff, 0x00, 0x3f, 0xff, 0xff, 0xe0, 0x18, 0xff, 0xff, 0x00, 0x1f, 0xc0, 0x3f, 0xe4, 0x30, 0xff,
0xff, 0x00, 0x1f, 0xc0, 0x3f, 0xe0, 0x18, 0xff, 0xff, 0x00, 0x1f, 0xc0, 0x7f, 0xe0, 0x20, 0xff,
0xff, 0x04, 0x1f, 0xe0, 0x7f, 0xe0, 0x08, 0xff, 0xff, 0x00, 0x0f, 0xfd, 0xff, 0xc0, 0x14, 0xff,
0xff, 0x00, 0x0f, 0xff, 0xff, 0xc0, 0x00, 0xff, 0xff, 0x00, 0x0f, 0xc0, 0x3f, 0x80, 0x00, 0xff,
0xff, 0x00, 0x07, 0x0d, 0x8f, 0x80, 0x09, 0xff, 0xff, 0x00, 0x02, 0x0f, 0x6f, 0x00, 0x04, 0xff,
0xff, 0x00, 0x00, 0x00, 0x14, 0x00, 0x08, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xff,
0xff, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xf6, 0x80, 0x00, 0xff,
0xff, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0xff,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff,
0xff, 0x00, 0x00, 0x00, 0x03, 0x88, 0x10, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, 0x4f, 0x24, 0xff,
0xff, 0x00, 0x00, 0x00, 0x0f, 0xcf, 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1f, 0xdf, 0xfc, 0xff,
0xff, 0x00, 0x00, 0x00, 0x1f, 0x8e, 0xd8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x7f, 0x9f, 0xfc, 0xff,
};
const unsigned char mugg_1[] PROGMEM = {
0x00, 0x00, 0x04, 0x92, 0x04, 0x81, 0x00, 0x00, 0x00, 0x4a, 0x98, 0x20, 0x86, 0xf8, 0x10, 0x00,
0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x92, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x30, 0x24, 0x00, 0x00, 0x80, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x92, 0x00,
0x00, 0x22, 0x20, 0x00, 0x00, 0x12, 0x09, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x08, 0x12, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
0x00, 0x12, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x81, 0xf8, 0x01, 0x30, 0x00,
0x00, 0x00, 0x00, 0x43, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x11, 0x07, 0xff, 0x80, 0x40, 0x00, 0x00, 0x00, 0x01, 0x0f, 0xff, 0xc0, 0x04, 0x00,
0x00, 0x00, 0x23, 0x0f, 0xff, 0xe0, 0x50, 0x00, 0x00, 0x00, 0x22, 0x1f, 0xff, 0xa0, 0x24, 0x00,
0x00, 0x80, 0x02, 0x1f, 0xff, 0xa0, 0x08, 0x00, 0x00, 0x00, 0x06, 0x3f, 0xff, 0xa0, 0x04, 0x00,
0x00, 0x80, 0x04, 0x3f, 0xff, 0xa0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfe, 0xa0, 0x10, 0x00,
0x00, 0x80, 0x00, 0x1f, 0x83, 0x20, 0x09, 0x00, 0x00, 0x00, 0x08, 0x8f, 0xff, 0xf0, 0x06, 0x00,
0x00, 0x00, 0x01, 0x0f, 0xe1, 0xf0, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x4f, 0xc1, 0x30, 0x04, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xd0, 0x30, 0x09, 0x00, 0x00, 0x00, 0x03, 0xff, 0xfb, 0x70, 0x22, 0x00,
0x00, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x01, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x00, 0x00,
0x00, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x01, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x02, 0x00,
0x00, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x80, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0xff, 0xe0, 0x18, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0x3f, 0xe4, 0x30, 0x00,
0x00, 0x00, 0x1f, 0xc0, 0x3f, 0xe0, 0x18, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0x7f, 0xe0, 0x20, 0x00,
0x00, 0x04, 0x1f, 0xe0, 0x7f, 0xe0, 0x08, 0x00, 0x00, 0x00, 0x0f, 0xfd, 0xff, 0xc0, 0x14, 0x00,
0x00, 0x00, 0x0f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x3f, 0x80, 0x00, 0x00,
0x00, 0x00, 0x07, 0x0d, 0x8f, 0x80, 0x09, 0x00, 0x00, 0x00, 0x02, 0x0f, 0x6f, 0x00, 0x04, 0x00,
0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf6, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x88, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x4f, 0x24, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xcf, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xdf, 0xfc, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x8e, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x9f, 0xfc, 0x00,
};
int button[] = { 0, 1, 2, 3, 4, 5, 6, 7};
int buttonState[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
int lastButtonState[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
#define NUMBUTTONS sizeof(button)
// // Instantiate a Bounce object
// Bounce debouncer[NUMBUTTONS] = {
// Bounce(),
// Bounce(),
// Bounce(),
// Bounce(),
// Bounce(),
// Bounce(),
// Bounce(),
// Bounce()
// };
// #define BUTTON_PIN_0 0
// int buttonState = LOW;
// int button = 0;
// // Instantiate a Bounce object
// Bounce debouncer = Bounce();
void setup(void) {
tft.begin();
tft.fillScreen(BLACK);
textBox(0, 1, VERSION, YELLOW);
delay(500);
tft.drawBitmap(32, 32, mugg_1, 64, 64, RED);
// initialize the LED pin as an output:
pinMode(heartPin, OUTPUT);
textBox(0, 1, "Heartbeat initalized.", YELLOW);
heartBeat(1);
delay(500);
if (! musicPlayer.begin()) { // initialise the music player
textBox(0, 1, "Couldn't find VS1053, HALT!", RED);
while (1); // don't do anything more
}
textBox(0, 1, "VS1053 found.", YELLOW);
musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working
delay(500);
if (!SD.begin(VS1053_CARDCS)) {
textBox(0, 1, "SD failed, or not present, HALT!", RED);
while (1); // don't do anything more
}
textBox(0, 1, "SD OK.", YELLOW);
delay(500);
// Set volume for left, right channels. lower numbers == louder volume!
//musicPlayer.setVolume(20, 20);
musicPlayer.setVolume(volume[0], volume[1]);
/***** Two interrupt options! *******/
// This option uses timer0, this means timer1 & t2 are not required
// (so you can use 'em for Servos, etc) BUT millis() can lose time
// since we're hitchhiking on top of the millis() tracker
//musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT);
// This option uses a pin interrupt. No timers required! But DREQ
// must be on an interrupt pin. For Uno/Duemilanove/Diecimilla
// that's Digital #2 or #3
// See http://arduino.cc/en/Reference/attachInterrupt for other pins
// *** This method is preferred
if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT)){
textBox(0, 1, "DREQ pin is not an interrupt pin", YELLOW);
} else {
textBox(0, 1, "DREQ pin is an interrupt pin", YELLOW);
}
delay(500);
// initialize the pushbutton pins as input:
// for (int playerPinSelect = 0; playerPinSelect < pinCount; playerPinSelect++) {
// musicPlayer.GPIO_pinMode(playerGPIO[playerPinSelect], INPUT);
// delay(100);
// }
// for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
// musicPlayer.GPIO_pinMode(button[pinSelect], INPUT);
// delay(100);
// debouncer[pinSelect].attach(button[pinSelect]);
// debouncer[pinSelect].interval(5); // interval in ms
// }
// Setup the buttons with as inputs :
for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
musicPlayer.GPIO_pinMode(button[pinSelect], INPUT);
delay(100);
}
// // After setting up the button, setup the Bounce instance :
// debouncer.attach(BUTTON_PIN_0);
// debouncer.interval(5); // interval in ms
// Setup the first button with an internal pull-up :
//pinMode(BUTTON_PIN_1,INPUT_PULLUP);
// After setting up the button, setup the Bounce instance :
textBox(TOP, PRINT, "musicPlayer.GPIO initalized.", YELLOW);
delay(500);
heartBeat(0);
textBox(TOP, PRINT, "Test - 7 - check", BLUE);
Serial.begin(9600);
Serial.println("hello!");
}
void loop() {
// Update the Bounce instances :
//debouncer.update();
// Get the updated value :
// int value = debouncer.read();
//int value = musicPlayer.GPIO_digitalRead(0);
//int buttonState[] = {0, 0, 0, 0, 0, 0, 0, 0};
for (int pinSelect = 0; pinSelect < 8; pinSelect++) {
buttonState[pinSelect] = musicPlayer.GPIO_digitalRead(pinSelect);
}
if (array_cmp(lastButtonState, buttonState, 8, 8) == true){
// do this if they are equal
}else{
// do this if they are different
for (int pinSelect = 0; pinSelect < 8; pinSelect++) {
if (pinSelect == 0){
Serial.print("{");
}
Serial.print(buttonState[pinSelect]);
if (pinSelect == 7){
Serial.println("}");
}
else {
Serial.print(", ");
}
}
}
memcpy( lastButtonState, buttonState, 8 );
// // Turn on the LED if either button is pressed :
// if (buttonState[pinSelect] == HIGH) {
// heartBeat(0);
// }
// else {
// heartBeat(1);
// }
// }
//
// Serial.println("");
// Turn on the LED if either button is pressed :
// if ( value == LOW ) {
// heartBeat(0);
// }
// else {
// heartBeat(1);
// }
//Serial.println(value);
// for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
// // Update the Bounce instances :
// debouncer[pinSelect].update();
// // Get the updated value :
// buttonState[pinSelect] = debouncer[pinSelect].read();
// }
//
// for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
// // Turn on the LED if either button is pressed :
// if (buttonState[pinSelect] == HIGH) {
// heartBeat(0);
// }
// else {
// heartBeat(1);
// }
// }
//
// for (int pinSelect = 0; pinSelect < NUMBUTTONS; pinSelect++) {
// Serial.print(buttonState[pinSelect]);
// Serial.print(", ");
// // Turn on the LED if either button is pressed :
// if (buttonState[pinSelect] == HIGH) {
// heartBeat(0);
// }
// else {
// heartBeat(1);
// }
// }
//
// Serial.println("");
// check_switches(); // when we check the switches we'll get the current state
//
// for (byte i = 0 i if (justpressed[i]) {
// Serial.print(i, DEC);
// Serial.println(" Just pressed");
// // remember, check_switches() will CLEAR the 'just pressed' flag
// }
// if (justreleased[i]) {
// Serial.print(i, DEC);
// Serial.println(" Just released");
// // remember, check_switches() will CLEAR the 'just pressed' flag
// }
// if (pressed[i]) {
// Serial.print(i, DEC);
// Serial.println(" pressed");
// // is the button pressed down at this moment
// }
/* heartBeat(0);
* delay(200);
* heartBeat(1);
* delay(200);
*/
/*playergpio
* int playerGPIO[] = {0, 1, 2, 3, 4, 5, 6, 7};
* int playerPinSelect = 0;
* musicPlayer.GPIO_pinMode(playerGPIO[playerPinSelect], OUTPUT);
* musicPlayer.GPIO_pinMode(playerGPIO[playerPinSelect], INPUT);
* musicPlayer.GPIO_digitalWrite(playerGPIO[playerPinSelect], HIGH);
* musicPlayer.GPIO_digitalWrite(playerGPIO[playerPinSelect], LOW);
* musicPlayer.GPIO_digitalRead(playerGPIO[playerPinSelect]);
*/
// delay (1000);
// tft.fillRect(0, 0, 128, 32, RED);
// delay (1000);
// tft.fillRect(32, 32, 64, 64, GREEN);
// delay (1000);
// tft.fillRect(0, 32, 32, 64, BLUE);
// delay (1000);
// tft.fillRect(0, 96, 128, 128, YELLOW);
// delay (1000);
// tft.fillRect(0, 0, 128, 32, WHITE);
// delay (1000);
// tft.fillRect(96, 32, 32, 64, MAGENTA);
// delay (1000);
//
//
// tft.fillScreen(BLACK);
// delay (1000);
//
// tft.fillRect(32, 32, 64, 64, CYAN);
// delay (1000);
// tft.fillRect(0, 0, 128, 32, MAGENTA);
// delay (1000);
// tft.fillRect(32, 32, 64, 64, BLUE);
// delay (1000);
// tft.fillRect(0, 32, 32, 64, YELLOW);
// delay (1000);
// tft.fillRect(0, 96, 128, 128, GREEN);
// delay (1000);
// tft.fillRect(96, 32, 32, 64, WHITE);
// delay (1000);
//
// tft.fillScreen(BLACK);
/*
/ / re*ad the state of the switch into a local variable:
int reading = 0;
// read the state of the pushbutton value:
for (int playerPinSelect = 0; playerPinSelect < pinCount; playerPinSelect++) {
reading = musicPlayer.GPIO_digitalRead(playerGPIO[playerPinSelect]);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState[playerPinSelect]) {
// reset the debouncing timer
lastDebounceTime[playerPinSelect] = millis();
}
if ((millis() - lastDebounceTime[playerPinSelect]) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState[playerPinSelect]) {
buttonState[playerPinSelect] = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState[playerPinSelect] == HIGH) {
//ledState = !ledState;
//digitalWrite(ledPin, HIGH);
switch (playerPinSelect) {
case 0: // PLAY
heartBeat(1);
//textBox(0, 1, "0", YELLOW);
tft.fillRect(0, 96, 128, 128, BLACK);
textBox(BOTTOM, PRINT, "CLEAR THE FUKN SCREEN!!!!", YELLOW);
//textBox(BOTTOM, PRINT, "PLAY", YELLOW);
//mediaButton(PLAY);
break;
case 1: // RECORD
heartBeat(1);
//textBox(0, 1, "1", YELLOW);
textBox(BOTTOM, PRINT, "1", YELLOW);
//textBox(TOP, CLEAR, "", BLACK);
//textBox(TOP, PRINT, "Record", YELLOW);
//mediaButton(RECORD);
break;
case 2: // STOP
heartBeat(1);
textBox(BOTTOM, PRINT, "2", YELLOW);
//textBox(TOP, PRINT, "2", YELLOW);
//textBox(TOP, PRINT, "STOP", YELLOW);
// mediaButton(STOP);
break;
case 3:
heartBeat(1);
textBox(BOTTOM, PRINT, "3", YELLOW);
//textBox(TOP, PRINT, "3", YELLOW);
break;
case 4:
heartBeat(1);
//textBox(BOTTOM, PRINT, "4", YELLOW);
tft.fillRect(0, 96, 128, 128, YELLOW);
//tft.fillRect(0, 0, 128, 32, BLACK);
tft.setCursor(0,96);
tft.setTextColor(RED);
tft.print("4");
//textBox(TOP, PRINT, "4", YELLOW);
break;
case 5:
heartBeat(1);
tft.fillRect(32, 32, 64, 64, BLACK);
textBox(BOTTOM, PRINT, "5", YELLOW);
//textBox(TOP, PRINT, "5", YELLOW);
break;
case 6:
heartBeat(1);
textBox(BOTTOM, PRINT, "6", YELLOW);
//textBox(TOP, PRINT, "6", YELLOW);
break;
case 7:
heartBeat(1);
textBox(BOTTOM, PRINT, "7", YELLOW);
//textBox(TOP, PRINT, "7", YELLOW);
break;
default:
break;
}
} else if (buttonState[playerPinSelect] == 0) {
//digitalWrite(ledPin, LOW);
switch (playerPinSelect) {
case 0:
//heartBeat(0);
//textBox(TOP, CLEAR, "", BLACK);
break;
case 1:
//heartBeat(0);
//textBox(TOP, CLEAR, "", BLACK);
break;
case 2:
//heartBeat(0);
//textBox(TOP, CLEAR, "", BLACK);
break;
case 3:
//heartBeat(0);
//textBox(TOP, CLEAR, "", BLACK);
break;
case 4:
//heartBeat(0);
//textBox(TOP, CLEAR, "", BLACK);
break;
case 5:
//heartBeat(0);
//textBox(TOP, CLEAR, "", BLACK);
break;
case 6:
//heartBeat(0);
//textBox(TOP, CLEAR, "", BLACK);
break;
case 7:
//heartBeat(0);
//textBox(TOP, CLEAR, "", BLACK);
break;
default:
break;
}
}
}
}
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState[playerPinSelect] = reading;
}*/
}
boolean array_cmp(int *a, int *b, int len_a, int len_b){
// where:
// a = first array
// b = second array
// len_a = number of elements (length) of array a
// len_b = number of elements (length) of array b
int n;
// if their lengths are different, return false
if (len_a != len_b) return false;
// test each element to be the same. if not, return false
for (n=0;n<len_a;n++) if (a[n]!=b[n]) return false;
//ok, if we have not returned yet, they are equal :)
return true;
}
void heartBeat(int beat){
if (beat == 1){
digitalWrite(heartPin, HIGH); // turn the LED on (HIGH is the voltage level)
} else if (beat == 0) {
digitalWrite(heartPin, LOW); // turn the LED off by making the voltage LOW
}
}
void textBox(int boxRegion, int textAction, char *text, uint16_t color){
switch (boxRegion) {
case TOP:{
switch (textAction) {
case CLEAR:{
tft.fillRect(0, 0, 128, 32, BLACK);
break;
}
case PRINT:{
tft.fillRect(0, 0, 128, 32, BLACK);
tft.setCursor(0,0);
tft.setTextColor(color);
tft.print(text);
break;
}
default:{
break;
}
}
break;
}
case BOTTOM:{
switch (textAction){
case CLEAR:{
tft.fillRect(0, 96, 128, 128, BLACK);
break;
}
case PRINT:{
tft.fillRect(0, 96, 128, 128, BLACK);
tft.setCursor(0,96);
tft.setTextColor(color);
tft.print(text);
break;
}
default:{
break;
}
}
break;
}
case LEFT:{
switch (textAction){
case CLEAR:{
tft.fillRect(0, 32, 32, 96, BLACK);
break;
}
case PRINT:{
tft.fillRect(0, 32, 32, 96, BLACK);
tft.setCursor(0,32);
tft.setTextColor(color);
tft.print(text);
break;
}
default:{
break;
}
}
break;
}
case RIGHT:{
switch (textAction){
case CLEAR:{
tft.fillRect(96, 32, 128, 96, BLACK);
break;
}
case PRINT:{
tft.fillRect(96, 32, 128, 96, BLACK);
tft.setCursor(96, 32);
tft.setTextColor(color);
tft.print(text);
break;
}
default:{
break;
}
}
break;
}
case CENTER:{
switch (textAction){
case CLEAR:{
tft.fillRect(32, 32, 96, 96, BLACK);
break;
}
case PRINT:{
tft.fillRect(32, 32, 96, 96, BLACK);
tft.setCursor(32, 32);
tft.setTextColor(color);
tft.print(text);
break;
}
default:{
break;
}
break;
}
default:{
break;
}
}
}
}
void mediaButton(int symbol) {
// https://learn.adafruit.com/adafruit-gfx-graphics-library?view=all
// void drawPixel(uint16_t x, uint16_t y, uint16_t color);
// void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
// void drawFastVLine(uint16_t x0, uint16_t y0, uint16_t length, uint16_t color);
// void drawFastHLine(uin86_t x0, uin86_t y0, uint8_t length, uint16_t color);
// void drawRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color);
// void fillRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color);
// void drawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);
// void fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);
// void drawRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color);
// void fillRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color);
// void drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
// void fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
// void drawChar(uint16_t x, uint16_t y, char c, uint16_t color, uint16_t bg, uint8_t size);
// void setCursor(uint16_t x0, uint16_t y0);
// void setTextColor(uint16_t color);
// void setTextColor(uint16_t color, uint16_t backgroundcolor);
// void setTextSize(uint8_t size);
// void setTextWrap(boolean w);
// void fillScreen(uint16_t color);
// void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
// void setRotation(uint8_t rotation); //The rotation parameter can be 0, 1, 2 or 3.
// uint16_t width();
// uint16_t height();
// int16_t x1, y1;
// uint16_t w, h;
// tft.getTextBounds(string, x, y, &y1, &y1, &w, &h);
switch (symbol) {
case PLAY:
tft.fillRect(32, 32, 64, 64, BLACK);
tft.fillTriangle(32, 32, 32, 94, 94, 64, GREEN);
break;
case RECORD:
tft.fillRect(32, 32, 64, 64, BLACK);
tft.fillCircle(62, 62, 30, RED);
break;
case STOP:
tft.fillRect(32, 32, 64, 64, BLACK);
tft.fillRect(32, 32, 64, 64, BLUE);
break;
case PAUSE:// pause
tft.fillRoundRect(25, 90, 78, 60, 8, WHITE);
tft.fillRoundRect(39, 98, 20, 45, 5, GREEN);
tft.fillRoundRect(69, 98, 20, 45, 5, GREEN);
break;
case 4:
break;
case 5 :
break;
case 6 :
break;
case 7 :
break;
default:
break;
}
}
// void check_switches()
// {
// static byte previousstate[NUMBUTTONS];
// static byte currentstate[NUMBUTTONS];
// static long lasttime;
// byte index;
//
// if (millis() // we wrapped around, lets just try again
// lasttime = millis();
//
//
// if ((lasttime + DEBOUNCE) > millis()) {
// // not enough time has passed to debounce
// return;
// }
// // ok we have waited DEBOUNCE milliseconds, lets reset the timer
// lasttime = millis();
//
// for (index = 0; index // when we start, we clear out the "just" indicators
// justreleased[index] = 0;
//
// currentstate[index] = digitalRead(buttons[index]); // read the button
//
// /*
// * Serial.print(index, DEC);
// * Serial.print(": cstate=");
// * Serial.print(currentstate[index], DEC);
// * Serial.print(", pstate=");
// * Serial.print(previousstate[index], DEC);
// * Serial.print(", press=");
// */
//
// if (currentstate[index] == previousstate[index]) {
// if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
// // just pressed
// justpressed[index] = 1;
// }
// else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
// // just released
// justreleased[index] = 1;
// }
// pressed[index] = !currentstate[index]; // remember, digital HIGH means NOT pressed
// }
// //Serial.println(pressed[index], DEC);
// previousstate[index] = currentstate[index]; // keep a running tally of the buttons
// }
// void drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
// const unsigned char myBitmap [] PROGMEM = {
// 0xff, 0x00, 0x04, 0x92, 0x04, 0x81, 0x00, 0xff, 0xff, 0x4a, 0x98, 0x20, 0x86, 0xf8, 0x10, 0xff,
// 0xff, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0x48, 0x92, 0x00, 0x00, 0x00, 0x10, 0xff,
// 0xff, 0x30, 0x24, 0x00, 0x00, 0x80, 0x08, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x08, 0x92, 0xff,
// 0xff, 0x22, 0x20, 0x00, 0x00, 0x12, 0x09, 0xff, 0xff, 0x09, 0x00, 0x00, 0x00, 0x08, 0x12, 0xff,
// 0xff, 0x10, 0x00, 0x00, 0x00, 0x00, 0x05, 0xff, 0xff, 0x09, 0x00, 0x00, 0x00, 0x01, 0x02, 0xff,
// 0xff, 0x12, 0x00, 0x00, 0x00, 0x02, 0x05, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0xff,
// 0xff, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x01, 0xff, 0xff, 0x00, 0x01, 0x81, 0xf8, 0x01, 0x30, 0xff,
// 0xff, 0x00, 0x00, 0x43, 0xfc, 0x00, 0x00, 0xff, 0xff, 0x00, 0x01, 0x07, 0xff, 0x00, 0x00, 0xff,
// 0xff, 0x00, 0x11, 0x07, 0xff, 0x80, 0x40, 0xff, 0xff, 0x00, 0x01, 0x0f, 0xff, 0xc0, 0x04, 0xff,
// 0xff, 0x00, 0x23, 0x0f, 0xff, 0xe0, 0x50, 0xff, 0xff, 0x00, 0x22, 0x1f, 0xff, 0xa0, 0x24, 0xff,
// 0xff, 0x80, 0x02, 0x1f, 0xff, 0xa0, 0x08, 0xff, 0xff, 0x00, 0x06, 0x3f, 0xff, 0xa0, 0x04, 0xff,
// 0xff, 0x80, 0x04, 0x3f, 0xff, 0xa0, 0x08, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xfe, 0xa0, 0x10, 0xff,
// 0xff, 0x80, 0x00, 0x1f, 0x83, 0x20, 0x09, 0xff, 0xff, 0x00, 0x08, 0x8f, 0xff, 0xf0, 0x06, 0xff,
// 0xff, 0x00, 0x01, 0x0f, 0xe1, 0xf0, 0x0b, 0xff, 0xff, 0x00, 0x00, 0x4f, 0xc1, 0x30, 0x04, 0xff,
// 0xff, 0x00, 0x00, 0x3f, 0xd0, 0x30, 0x09, 0xff, 0xff, 0x00, 0x03, 0xff, 0xfb, 0x70, 0x22, 0xff,
// 0xff, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x00, 0xff,
// 0xff, 0x00, 0x7f, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x02, 0xff,
// 0xff, 0x00, 0x7f, 0xff, 0xff, 0xf0, 0x00, 0xff, 0xff, 0x80, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0xff,
// 0xff, 0x00, 0x3f, 0xff, 0xff, 0xe0, 0x18, 0xff, 0xff, 0x00, 0x1f, 0xc0, 0x3f, 0xe4, 0x30, 0xff,
// 0xff, 0x00, 0x1f, 0xc0, 0x3f, 0xe0, 0x18, 0xff, 0xff, 0x00, 0x1f, 0xc0, 0x7f, 0xe0, 0x20, 0xff,
// 0xff, 0x04, 0x1f, 0xe0, 0x7f, 0xe0, 0x08, 0xff, 0xff, 0x00, 0x0f, 0xfd, 0xff, 0xc0, 0x14, 0xff,
// 0xff, 0x00, 0x0f, 0xff, 0xff, 0xc0, 0x00, 0xff, 0xff, 0x00, 0x0f, 0xc0, 0x3f, 0x80, 0x00, 0xff,
// 0xff, 0x00, 0x07, 0x0d, 0x8f, 0x80, 0x09, 0xff, 0xff, 0x00, 0x02, 0x0f, 0x6f, 0x00, 0x04, 0xff,
// 0xff, 0x00, 0x00, 0x00, 0x14, 0x00, 0x08, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xff,
// 0xff, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xf6, 0x80, 0x00, 0xff,
// 0xff, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0xff,
// 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
// 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff,
// 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff,
// 0xff, 0x00, 0x00, 0x00, 0x03, 0x88, 0x10, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, 0x4f, 0x24, 0xff,
// 0xff, 0x00, 0x00, 0x00, 0x0f, 0xcf, 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1f, 0xdf, 0xfc, 0xff,
// 0xff, 0x00, 0x00, 0x00, 0x1f, 0x8e, 0xd8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x7f, 0x9f, 0xfc, 0xff,
// };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment