Control-Surface icon indicating copy to clipboard operation
Control-Surface copied to clipboard

Added NotePiezo, MIDIPiezo, and Piezo classes.

Open aamott opened this issue 3 years ago • 4 comments

These classes add the ability to use Piezos (or other analog, voltage-outputting sensors) to produce a note. Useful for velocity sensitive drums.

aamott avatar Mar 22 '21 19:03 aamott

Hi! How Can I use those classes? Can you write examples?

kentforth avatar Jun 03 '21 14:06 kentforth

Absolutely! At its most basic, code would look like this:

#include <Control_Surface.h>

// this starts a hairlessMIDI_Interface connection. If you have an arduino pro 
//    or another that supports the Keyboard library, you can use USBMIDI_Interface midi;
//    If you use HairlessMIDI_Interface, you have to install hairlessMIDISerial.
HairlessMIDI_Interface midi;

// Pin A1 {note 36, CHANNEL_10 is drums}
NotePiezo piezo1 = { A1, {36, CHANNEL_10} };
NotePiezo piezo2 = { A2, {38, CHANNEL_10} };
// the same concept but with a button
NoteButton button = { 7, {42, CHANNEL_1} };


void setup() {
  Control_Surface.begin();

  // this just sets the minimum threshold automatically so it doesn't register sitting there as a hit.
  piezo1.setHitThreshold(piezo1.sampleSilence(1000)+1);
  piezo2.setHitThreshold(piezo2.sampleSilence(1000)+1);
}

void loop() {
  Control_Surface.loop();
}

If you want to install hairless midi, you can get it here: Hairless MIDI Serial And if you're using Windows, not Linux, you also have to install LoopMIDI. You start loopMIDI and plug in the Arduino, then start hairlessMIDISerial and choose the Arduino on the left and the loopMIDI device on the right.

aamott avatar Jun 03 '21 23:06 aamott

Absolutely! At its most basic, code would look like this:

#include <Control_Surface.h>

// this starts a hairlessMIDI_Interface connection. If you have an arduino pro 
//    or another that supports the Keyboard library, you can use USBMIDI_Interface midi;
//    If you use HairlessMIDI_Interface, you have to install hairlessMIDISerial.
HairlessMIDI_Interface midi;

// Pin A1 {note 36, CHANNEL_10 is drums}
NotePiezo piezo1 = { A1, {36, CHANNEL_10} };
NotePiezo piezo2 = { A2, {38, CHANNEL_10} };
// the same concept but with a button
NoteButton button = { 7, {42, CHANNEL_1} };


void setup() {
  Control_Surface.begin();

  // this just sets the minimum threshold automatically so it doesn't register sitting there as a hit.
  piezo1.setHitThreshold(piezo1.sampleSilence(1000)+1);
  piezo2.setHitThreshold(piezo2.sampleSilence(1000)+1);
}

void loop() {
  Control_Surface.loop();
}

Hello, I'm trying to connect a piezo using your example, but the compiler throws an error:

Arduino: 1.8.13 (Windows 10), Плата:"Arduino Uno" sketch_mar20a:9:1: error: 'NotePiezo' does not name a type NotePiezo piezo1 = { A1, {36, CHANNEL_10} }; ^~~~~~~~~ sketch_mar20a:10:1: error: 'NotePiezo' does not name a type NotePiezo piezo2 = { A2, {38, CHANNEL_10} }; ^~~~~~~~~ C:\Users\User\AppData\Local\Temp\arduino_modified_sketch_55327\sketch_mar20a.ino: In function 'void setup()': sketch_mar20a:19:3: error: 'piezo1' was not declared in this scope piezo1.setHitThreshold(piezo1.sampleSilence(1000)+1); ^~~~~~ sketch_mar20a:20:3: error: 'piezo2' was not declared in this scope piezo2.setHitThreshold(piezo2.sampleSilence(1000)+1); ^~~~~~ exit status 1 'NotePiezo' does not name a type

milkos86 avatar Mar 19 '22 22:03 milkos86

Are you using my fork or the main repo? Only mine supports piezo input.

aamott avatar Mar 22 '22 00:03 aamott