如何让 Flora MIDI 鼓手套与 Arduino 一起使用?

How do I get the Flora MIDI Drum Glove to work with Arduino?

提问人:Vandenbosch Emmett L 提问时间:11/14/2023 最后编辑:the busybeeVandenbosch Emmett L 更新时间:11/14/2023 访问量:17

问:

对于我的项目,我正在尝试使用 Arduino IDE 2.1.1 创建 FLORA MIDI 鼓手套的原型。

较旧的教程Flora MIDI 鼓手套

更新Flora MIDI 鼓手套

我将 4 个压电电阻和 4 兆欧电阻连接到面包板,连接到 A0、A1、A2 和 A3。我下载了 PJRC 的 Teensyduino 软件包和 TeeOnArdu 软件包。然后,我将“TeeOnArdu”文件夹从TeeOnArdu-master.zip文件移动到Arduino速写本中的“硬件”文件夹。我还将代码从 A9、A7、A10 和 A11 更改为 A0、A1、A2 和 A3。在运行代码之前,我将开发板设置为“Teensy 2.0”,将 USB 类型设置为“MIDI”。

我运行了它,但它给出了这个错误:

/Users/smithe3/Desktop/UPDATED_MIDI/UPDATED_MIDI.ino: In function 'void setup()':
/Users/smithe3/Desktop/UPDATED_MIDI/UPDATED_MIDI.ino:24:3: error: 'Keyboard' was not declared in this scope
   Keyboard.begin();
   ^~~~~~~~
/Users/smithe3/Desktop/UPDATED_MIDI/UPDATED_MIDI.ino: In function 'void loop()':
/Users/smithe3/Desktop/UPDATED_MIDI/UPDATED_MIDI.ino:42:7: error: 'Keyboard' was not declared in this scope
       Keyboard.press(Keys[i]);
       ^~~~~~~~
/Users/smithe3/Desktop/UPDATED_MIDI/UPDATED_MIDI.ino:50:7: error: 'Keyboard' was not declared in this scope
       Keyboard.release(Keys[i]);
       ^~~~~~~~

exit status 1

Compilation error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

我还没有用于我正在制作的手套的 Flora 微控制器,所以请告诉我是否有办法解决此问题:)

我提供了以下代码:

/*
Piezo Keyboard glove
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
Written by Limor Fried & Becky Stern for Adafruit Industries. BSD license, all text above must be included in any redistribution
*/

const int indexFinger = A0; // the piezo is connected to analog pin 9 (aka D9)
const int middleFinger = A1; // the piezo is connected to analog pin 7 (aka D6)
const int thumb = A2; // the piezo is connected to analog pin 10 (aka D10)
const int pinkyFinger = A3; // the piezo is connected to analog pin 11 (aka D12)

const int pins[] = { thumb, indexFinger, middleFinger, pinkyFinger };

char Keys[] = { 'z', 'x', 'c', 'v' };

boolean currentPressed[] = { false, false, false, false };

const int threshold = 40; // threshold value to decide when the detected sound is a knock or not

void setup()
{
  //while (!Serial)
  Serial.begin(115200);
  Serial.println("start");
  Keyboard.begin();
}

void loop()
{
  for (int i = 0; i < 4; i++) {
    delay(1);
    long total1 = 0;
    long start = millis();
    long total = analogRead(pins[i]);

    // check if we are sensing that a finger is touching
    // and that it wasnt already pressed
    if ((total > threshold) && (!currentPressed[i])) {
      Serial.print("Key pressed #");
      Serial.print(i);
      Serial.print(" (");
      Serial.print(Keys[i]);
      Serial.println(")");
      currentPressed[i] = true;
    
      Keyboard.press(Keys[i]);
    }
    else if ((total <= threshold) && (currentPressed[i])) {
      // key was released (no touch, and it was pressed before)
      Serial.print("Key released #");
      Serial.print(i);
      Serial.print(" (");
      Serial.print(Keys[i]);
      Serial.println(")");
      currentPressed[i] = false;
      
      Keyboard.release(Keys[i]);
    }
    delay(5);
  }
}

我尝试将 Teensy 的版本从 1.58.1 更改为 1.57.2 并再次运行它。我还尝试将开发板切换回 Arduino Uno 和 Teensy 2.0、Teensy 4.0、Teensy++ 2.0 等。

微控制器 Arduino-Uno Adafruit 电路 可穿戴设备

评论

1赞 pmacfarlane 11/14/2023
正如错误消息所说:似乎你没有。Does your sketch include the line '#include <Keyboard.h>'?
0赞 Vandenbosch Emmett L 11/20/2023
@pmacfarlane 您会在哪里插入 <Keyboard.h>?
0赞 pmacfarlane 11/20/2023
您将在源文件的顶部插入。#include <Keyboard.h>

答: 暂无答案