Estoy intentando hacer un proyecto con un arduino ESP32 usando el touch, para que genere sonido al ponerlo en contacto con diferentes cosas, por lo que lo estoy configurando en Arduino IDE, con la libreria Adafruit_TinyUSB, pero me aparece el siguiente error:
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino: In function 'void setup()':*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:41:8: error: 'TinyUSBDevice' was not declared in this scope*
* 41 | if (!TinyUSBDevice.isInitialized()) {*
* | ^~~~~*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:45:11: error: 'LED_BUILTIN' was not declared in this scope*
* 45 | pinMode(LED_BUILTIN, OUTPUT);*
* | ^~~~~*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:47:12: error: 'class Adafruit_USBH_CDC' has no member named 'setStringDescriptor'*
* 47 | usb_midi.setStringDescriptor("TinyUSB MIDI");*
* | ^~~~~~~*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:55:24: error: 'handleNoteOn' was not declared in this scope*
* 55 | MIDI.setHandleNoteOn(handleNoteOn);*
* | ^~~~~~*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:58:25: error: 'handleNoteOff' was not declared in this scope*
* 58 | MIDI.setHandleNoteOff(handleNoteOff);*
* | ^~~~~*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino: In function 'void loop()':*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:70:8: error: 'TinyUSBDevice' was not declared in this scope*
* 70 | if (!TinyUSBDevice.mounted()) {*
* | ^~~~~*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:88:2: error: '¨' was not declared in this scope*
* 88 | {¨*
* | ^*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:98:2: error: '¨' was not declared in this scope*
* 98 | {¨*
* | ^*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:120:60: error: a function-definition is not allowed here before '{' token*
* 120 | void handleNoteOn(byte channel, byte pitch, byte velocity) {*
* | ^*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:132:61: error: a function-definition is not allowed here before '{' token*
* 132 | void handleNoteOff(byte channel, byte pitch, byte velocity) {*
* | ^*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:142:2: error: expected '}' at end of input*
* 142 | }*
* | ^*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:75:34: note: to match this '{'*
* 75 | if (millis() - start_ms > 266) {*
* | ^*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:142:2: error: expected '}' at end of input*
* 142 | }*
* | ^*
*C:\Users\HP\AppData\Local\Temp\.arduinoIDE-unsaved2024530-12392-1my3xjt.gm7z\midi_test\midi_test.ino:63:13: note: to match this '{'*
* 63 | void loop() {*
* | ^*
*exit status 1*
*Compilation error: 'TinyUSBDevice' was not declared in this scope*
No sé como arreglarlo porque soy nueva en el asunto de configurar arduinos, este es el codigo que use completo:
#include <Arduino.h>
#include <Adafruit_TinyUSB.h>
#include <MIDI.h>
// USB MIDI object
Adafruit_USBH_CDC usb_midi;
// Create a new instance of the Arduino MIDI Library,
// and attach usb_midi as the transport.
MIDI_CREATE_INSTANCE(Adafruit_USBH_CDC, usb_midi, MIDI);
// Variable that holds the current position in the sequence.
uint32_t position = 0;
// Store example melody as an array of note values
byte note_sequence[] = {
74, 78, 81, 86, 90, 93, 98, 102, 57, 61, 66, 69, 73, 78, 81, 85, 88, 92, 97, 100, 97, 92, 88, 85, 81, 78,
74, 69, 66, 62, 57, 62, 66, 69, 74, 78, 81, 86, 90, 93, 97, 102, 97, 93, 90, 85, 81, 78, 73, 68, 64, 61,
56, 61, 64, 68, 74, 78, 81, 86, 90, 93, 98, 102
};
void setup() {
// Manual begin() is required on core without built-in support e.g. mbed rp2040
if (!TinyUSBDevice.isInitialized()) {
TinyUSBDevice.begin(0);
}
pinMode(LED_BUILTIN, OUTPUT);
usb_midi.setStringDescriptor("TinyUSB MIDI");
// Initialize MIDI, and listen to all MIDI channels
// This will also call usb_midi's begin()
MIDI.begin(MIDI_CHANNEL_OMNI);
// Attach the handleNoteOn function to the MIDI Library. It will
// be called whenever the Bluefruit receives MIDI Note On messages.
MIDI.setHandleNoteOn(handleNoteOn);
// Do the same for MIDI Note Off messages.
MIDI.setHandleNoteOff(handleNoteOff);
Serial.begin(115200);
}
void loop() {
#ifdef TINYUSB_NEED_POLLING_TASK
// Manual call tud_task since it isn't called by Core's background
TinyUSBDevice.task();
#endif
// not enumerated()/mounted() yet: nothing to do
if (!TinyUSBDevice.mounted()) {
return;
}
static uint32_t start_ms = 0;
if (millis() - start_ms > 266) {
start_ms += 266;
// Setup variables for the current and previous
// positions in the note sequence.
int previous = position - 1;
// If we currently are at position 0, set the
// previous position to the last note in the sequence.
if (previous < 0) {
previous = sizeof(note_sequence) - 1;
}
if (touchRead(33)<60)
{¨
t0 = millis () ;
// Send Note On for current position at full velocity (127) on channel 1.
MIDI.sendNoteOn(60+touchRead(33), 100, 1);
}else {
// Send Note Off for previous note.
MIDI.sendNoteOff(60+touchRead(33), 100, 1);
{
if (touchRead(32)<60)
{¨
t0 = millis () ;
// Send Note On for current position at full velocity (127) on channel 1.
MIDI.sendNoteOn(60+touchRead(32), 100, 1);
// Send Note Off for previous note.
MIDI.sendNoteOff(60+touchRead(32), 100, 1);
}
// Increment position
position++;
// If we are at the end of the sequence, start over.
if (position >= sizeof(note_sequence)) {
position = 0;
}
}
// read any new MIDI messages
MIDI.read();
}
void handleNoteOn(byte channel, byte pitch, byte velocity) {
// Log when a note is pressed.
Serial.print("Note on: channel = ");
Serial.print(channel);
Serial.print(" pitch = ");
Serial.print(pitch);
Serial.print(" velocity = ");
Serial.println(velocity);
}
void handleNoteOff(byte channel, byte pitch, byte velocity) {
// Log when a note is released.
Serial.print("Note off: channel = ");
Serial.print(channel);
Serial.print(" pitch = ");
Serial.print(pitch);
Serial.print(" velocity = ");
Serial.println(velocity);
}