-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conect 2 or more buttons to a single led #97
Comments
The MIDI Controller library doesn't support this, Control Surface does. What do you want the LED to do? |
Just turn on and off whenever a button is pressed |
You could do something like this: #include <Control_Surface.h> // Include the Control Surface library
// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;
using namespace MIDI_Notes;
// Instantiate an array of NoteButton objects
Array<NoteButton, 3> buttons = {{
// Push button on pin 5, note C4 (middle C) on MIDI channel 1
{5, {note(C, 4), CHANNEL_1}},
// Push button on pin 6, note D4 on MIDI channel 1
{6, {note(D, 4), CHANNEL_1}},
// etc.
{7, {note(E, 4), CHANNEL_1}},
}};
constexpr pin_t ledPin = LED_BUILTIN;
void setup() {
Control_Surface.begin(); // Initialize Control Surface
}
/// Return true if the predicate evaluates to true for at least one of the elements of the iterable
template<class Iterable, class Predicate> bool any_of(const Iterable &iterable, const Predicate &pred) {
for (auto iterator = iterable.begin(); iterator != iterable.end(); ++iterator)
if (pred(*iterator))
return true;
return false;
}
void loop() {
Control_Surface.loop(); // Update the Control Surface
// If any of the push buttons is pressed
bool pressed = any_of(buttons, [](const NoteButton &button) {
return button.getButtonState() == Button::Pressed;
});
// Turn on the LED
digitalWrite(ledPin, pressed);
} I don't have any hardware to test it at the moment, but it seems to compile without problems. |
Bussy week, today was the day i had to try this! /// Return true if the predicate evaluates to true for at least one of the elements of the iterable
template<class Iterable, class Predicate> bool any_of(const Iterable &iterable, const Predicate &pred) {
for (auto iterator = iterable.begin(); iterator != iterable.end(); ++iterator)
if (pred(*iterator))
return true;
return false;
} **im sory i dont know how to comment with code |
You can use the following to format the code:
The It is roughly based on the standard library |
Hi there, I am trying to connect digital 16 buttons to a single led and have the led turn on and off whenever any of the 16 button is pressed. I have tried adding control_surface mentioned above but is having hard time getting it to work. I'm not expert in coding, just wondering if anyone can help me out a bit? Mega-Control-Control-Final.zip
|
I added an example to Control Surface. See https://tttapa.github.io/Control-Surface-doc/Doxygen/de/d26/MIDI_controller-97_8ino-example.html I haven't tested it, since I don't have an Arduino Mega, but it compiles fine. |
Hi,
First, I want to start by thanking you for the tutorial on connecting 2 or
more buttons to a single LED.
I have tried the script you have provided and for the past two days and I
am still running one problem. Maybe I have missed something...
I was able to upload the script to Arduino Mega and it did compile
successfully. However, after this process, my controller no longer
respond, ie sending out midi messages, and the LEDs on the bank select no
longer works either.
My first thought was that the new script maybe did not include
the MIDI_Controller.h and therefore controller stopped working.
When I tried to add MIDI_Controller.h to the new script you have provided,
conflicts happened.
For another try, I tried to add the new script and
library Control_Surface.h to the old script I had, and same error happens.
The error log is very long, but I can provide to you if it is helpful.
Again, thank you for taking your time to help me and I am grateful.
I am wondering if you are able to continue helping me with this issue?
I have literally searched as much online, reading through tons of relevant
instructions and tutorials and find no straight forward solution.
You are the closest person I know that can possibly to get the LED to work
to the buttons.
Once again, thank you.
Respect,
Steve
https://www.underdogmodshop.com/
…On Tue, Dec 10, 2019 at 1:41 PM tttapa ***@***.***> wrote:
I added an example to Control Surface. See
https://tttapa.github.io/Control-Surface-doc/Doxygen/de/d26/MIDI_controller-97_8ino-example.html
I haven't tested it, since I don't have an Arduino Mega, but it compiles
fine.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#97?email_source=notifications&email_token=ANEHUW44AMLTKGPGHTXOY6DQYAEKFA5CNFSM4JFJCR3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGRBVQY#issuecomment-564271811>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANEHUW73BHD7KIAT7EC4PRTQYAEKFANCNFSM4JFJCR3A>
.
|
It looks like I forgot to add a MIDI interface to the example I posted earlier, my apologies. It should be fixed now. |
Hi,
I just ran this sketch and this is the error:
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board:
"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
C:\Users\panak\Documents\Arduino\libraries\Control-Surface-master\src\Control_Surface\Control_Surface_Class.cpp:
In member function 'onRealtimeMessage':
C:\Users\panak\Documents\Arduino\libraries\Control-Surface-master\src\Control_Surface\Control_Surface_Class.cpp:148:1:
internal compiler error: Segmentation fault
}
|
Well, that's unfortunate, it's a bug in the compiler. |
This is what I though too. I will try reinstall Arduino IDE. |
It seems to work on Linux using the Arduino IDE 1.8.9 and AVR Core version 1.8.1. |
Hi tttapa, It's working!!! You were absolutely correct with the Arduino IDE error, all I did was update the Arduino IDE to the newest version and problem solved. See it work here: https://youtu.be/o1qB8_DQy-U I have made some modification on the potentiometer part from change_channel to change_address.
|
Glad to hear! |
Hi
As I am looking at the examples from the Control_Surface on Github, I
cannot find an example on how to implement a rotary encoder like the one
on MIDI_controller.
I am just wondering if you are able to point me a direction to tutorial as
what I can do if I wish to add a rotary encoder?
Thank you so much
…On Fri, Dec 13, 2019 at 1:39 PM tttapa ***@***.***> wrote:
Glad to hear!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#97?email_source=notifications&email_token=ANEHUWYSR63HDEDQZVBZO33QYP6KHA5CNFSM4JFJCR3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEG3KMRI#issuecomment-565618245>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANEHUW5FKVODERZIVAGZ6ELQYP6KHANCNFSM4JFJCR3A>
.
|
You can use the There's no example yet, but you can find the arguments on the documentation page. #include <Encoder.h> // Include the Encoder library.
// This must be done before the Control Surface library.
#include <Control_Surface.h> // Include the Control Surface library
CCRotaryEncoder enc = {{2, 3}, {MCU::V_POT_1, CHANNEL_1}}; |
Hi there, I have a question regarding "Connecting 2 or more buttons to a single LED" I am trying to use matrix buttons alongside regular buttons. Is there a way to make the matrix buttons to work with This is what I have so far:
|
I'm not sure what you mean by that. A button matrix reads buttons, what does it have to do with a If you want to use matrix buttons as "regular" buttons, you have two options: inherit from the |
I dont know how to do it without making a mess with my signals.
The text was updated successfully, but these errors were encountered: