Hello everyone
I'm trying to build a simple Bluetooth controller
parts I have are
8 momentary ON/OFF switches
LOLIN32 Lite Board V1.0 con ESP-32 Rev1
the idea is to send ControlChange using Bluetooth
I've done this with an RPI Pico using USB and that was already complex to find information online
for this, I found many examples for noteOn noteOff but is quite confusing for me coming from a different platform
so hopefully someone can help out with the code in:
when a pushbutton is pressed once should send value 127
when pressed again should send value 0
I can add the code I have for the Pico but not sure how this will work with the Arduino interface as it seems that syntax is very different
please let me know if someone has tried this or has some example code, or any help will be highly appreciated
Uau!! that was a quick reply
Thank you
I will try this - will install your library and check some of the examples
here the code I am trying to emulate
this was done for the Pico using CircuitPython
import time
import board
import digitalio
import usb_midi
import adafruit_midi # MIDI protocol encoder/decoder library
from adafruit_midi.control_change import ControlChange
midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)
button1 = digitalio.DigitalInOut(board.GP13)
button1.switch_to_input(pull=digitalio.Pull.DOWN)
button2 = digitalio.DigitalInOut(board.GP12)
button2.switch_to_input(pull=digitalio.Pull.DOWN)
button3 = digitalio.DigitalInOut(board.GP11)
button3.switch_to_input(pull=digitalio.Pull.DOWN)
button4 = digitalio.DigitalInOut(board.GP10)
button4.switch_to_input(pull=digitalio.Pull.DOWN)
button5 = digitalio.DigitalInOut(board.GP18)
button5.switch_to_input(pull=digitalio.Pull.DOWN)
button6 = digitalio.DigitalInOut(board.GP19)
button6.switch_to_input(pull=digitalio.Pull.DOWN)
button7 = digitalio.DigitalInOut(board.GP20)
button7.switch_to_input(pull=digitalio.Pull.DOWN)
button8 = digitalio.DigitalInOut(board.GP21)
button8.switch_to_input(pull=digitalio.Pull.DOWN)
flag = 1
while True:
if button1.value and flag != 1:
midi.send(ControlChange(12, 127))
print("You sent ON")
flag = 1
time.sleep(0.75)
elif button1.value and flag != 0:
midi.send(ControlChange(12, 0))
print("you sent off")
flag = 0
time.sleep(0.75)
if button2.value and flag != 1:
midi.send(ControlChange(13, 127))
print("You sent ON")
flag = 1
time.sleep(0.75)
elif button2.value and flag != 0:
midi.send(ControlChange(13, 0))
print("you sent off")
flag = 0
time.sleep(0.75)
if button3.value and flag != 1:
midi.send(ControlChange(14, 127))
print("You sent ON")
flag = 1
time.sleep(0.75)
elif button3.value and flag != 0:
midi.send(ControlChange(14, 0))
print("you sent off")
flag = 0
time.sleep(0.75)
if button4.value and flag != 1:
midi.send(ControlChange(15, 127))
print("You sent ON")
flag = 1
time.sleep(0.75)
elif button4.value and flag != 0:
midi.send(ControlChange(15, 0))
print("you sent off")
flag = 0
time.sleep(0.75)
if button5.value and flag != 1:
midi.send(ControlChange(18, 127))
print("You sent ON")
flag = 1
time.sleep(0.75)
elif button5.value and flag != 0:
midi.send(ControlChange(18, 0))
print("you sent off")
flag = 0
time.sleep(0.75)
if button6.value and flag != 1:
midi.send(ControlChange(19, 127))
print("You sent ON")
flag = 1
time.sleep(0.75)
elif button6.value and flag != 0:
midi.send(ControlChange(19, 0))
print("you sent off")
flag = 0
time.sleep(0.75)
if button7.value and flag != 1:
midi.send(ControlChange(20, 127))
print("You sent ON")
flag = 1
time.sleep(0.75)
elif button7.value and flag != 0:
midi.send(ControlChange(20, 0))
print("you sent off")
flag = 0
time.sleep(0.75)
if button8.value and flag != 1:
midi.send(ControlChange(21, 127))
print("You sent ON")
flag = 1
time.sleep(0.75)
elif button8.value and flag != 0:
midi.send(ControlChange(21, 0))
print("you sent off")
flag = 0
time.sleep(0.75)
I know, I'm sure there would be a much cleaner way to do it
but as I mentioned before I'm very new to this and nevertheless it works on the pico via usb
trying to do the same using BLE midi with the esp32
Hey @PieterP
thank you again for the code and the library
one more question, only if its easy
I am using the code you sent, so the CCButtonLatched and it works beautifully
is there an easy way to add a LED to be powered when the ON signal is sent
as there is no visible way for me to say when the ON or OFF signal is sent
let me know if there is an integration with an LED per button
if there isn't not to worry
thank you again for this great implementation
do you have any examples? or will there be examples in the documents provided?
I will check anyway
thanx again and I really like your approach on the library
it seems well thought