美文网首页arduino
arduino 打鼓-DRUM

arduino 打鼓-DRUM

作者: Mr洋1 | 来源:发表于2019-08-11 10:43 被阅读19次

1.器材

  • RCA音频


    国产
    国外相同型号
  • CD盘


    cd

*1M 欧姆电阻


1M
  • PCB板


    PCB
  • 压电传感器
    piezo element


    piezo
element

2.电路图

线路

3. 焊接

注意需要讲GND线与piezo的GND的连接到arduino上,将其他线连接到arduino的模拟信号的引脚上。

图示

4.制作鼓盘

  • CD
    鼠标垫划开与CD大小一样,用胶水粘起来


    外壳
  • 将piezo放到CD中间


    place

    使用胶水注意不要将piezo弄湿,否则出错,读取不到数据,


    效果

5.连接PC

下载安装参考 上面网址进行配置

这里也可以参考 GitHub中的一篇文章
http://projectgus.github.io/hairless-midiserial/

6 .代码

#define LEDPIN     13     // status LED pin
#define PIEZOTHRESHOLD 5  // analog threshold for piezo sensing
#define PADNUM 6          // number of pads

int val;

void setup() {
  pinMode(LEDPIN, OUTPUT);
  Serial.begin(57600);   // set serial output rate
}

void loop() {

  // Loop through each piezo and send data
  // on the serial output if the force exceeds
  // the piezo threshold
  for(int i = 0; i < PADNUM; i++) {
    val = analogRead(i);
    if( val >= PIEZOTHRESHOLD ) {
      digitalWrite(LEDPIN,HIGH);  // indicate we're sending MIDI data
      Serial.print(i);
      Serial.print(",");
      Serial.print(val);
      Serial.println();
      digitalWrite(LEDPIN,LOW);
    }
  }
}

Hairless中的代码:

int pinRead;
char pinAssignments[16] ={
  'A0','A1','A2','A3','A4','A5','A6','A7','A8','A9','A10','A11'};
byte PadNote[16] = {
  57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72};         // MIDI notes from 0 to 127 (Mid C = 60)
int PadCutOff[16] = 
{
  400,400,200,800,400,400,400,400,400,400,400,400,400,400,400,400};           // Minimum Analog value to cause a drum hit
int MaxPlayTime[16] = {
  90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90};               // Cycles before a 2nd hit is allowed
#define  midichannel 1;                              // MIDI channel from 0 to 15 (+1 in "real world")
boolean VelocityFlag  = true;                           // Velocity ON (true) or OFF (false)

//*******************************************************************************************************************
// Internal Use Variables
//*******************************************************************************************************************
boolean activePad[16] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};                   // Array of flags of pad currently playing
int PinPlayTime[16] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};                     // Counter since pad started to play
byte status1;

int pin = 0;     
int hitavg = 0;
//*******************************************************************************************************************
// Setup
//*******************************************************************************************************************
void setup() 
{
  Serial.begin(57600);                                  // SET HAIRLESS TO THE SAME BAUD RATE IN THE SETTINGS

}
//*******************************************************************************************************************
// Main Program
//*******************************************************************************************************************
void loop() 
{
  for(int pin=0; pin < 16; pin++)                          //
  {
    //int pin = 3;
    //   for (pinRead=0; pinRead < 16, pin++){
    hitavg = analogRead(pinAssignments[pin]);  
    //Serial.println(hitavg);   
    // read the input pin

    if((hitavg > PadCutOff[pin]))
    {
      if((activePad[pin] == false))
      {
        if(VelocityFlag == true)
        {
          //          hitavg = 127 / ((1023 - PadCutOff[pin]) / (hitavg - PadCutOff[pin]));    // With full range (Too sensitive ?)
          hitavg = (hitavg / 8) -1 ;                                                 // Upper range
        }
        else
        {
          hitavg = 127;
        }
        MIDI_TX(144,PadNote[pin],hitavg); //note on

        PinPlayTime[pin] = 0;
        activePad[pin] = true;
      }
      else
      {
        PinPlayTime[pin] = PinPlayTime[pin] + 1;
      }
    }
    else if((activePad[pin] == true))
    {
      PinPlayTime[pin] = PinPlayTime[pin] + 1;
      if(PinPlayTime[pin] > MaxPlayTime[pin])
      {
        activePad[pin] = false;
        MIDI_TX(144,PadNote[pin],0); 
      }
    }
  } 
}

//*******************************************************************************************************************
// Transmit MIDI Message
//*******************************************************************************************************************
void MIDI_TX(byte MESSAGE, byte PITCH, byte VELOCITY) 
{
  status1 = MESSAGE + midichannel;
  Serial.write(status1);
  Serial.write(PITCH);
  Serial.write(VELOCITY);

}

相关文章

  • arduino 打鼓-DRUM

    1.器材 RCA音频国产国外相同型号 CD盘cd *1M 欧姆电阻 PCB板PCB 压电传感器piezo elem...

  • The Office-S05E10

    drum roll:a rapid succession of beats sounded on a drum, ...

  • 打鼓

    今天下班回来,对广场上的大鼓感起兴趣,忍不住上前死皮赖脸的讨要木槌,手舞足蹈地凭着感觉乱敲一气,大鼓师傅居然还给我...

  • 打鼓

  • 打鼓

    王敦年轻时,曾经被人称呼为乡巴佬,说的话也不是官话而是楚音方言。晋武帝司马炎召来当时的名流一起谈论技能才艺的事,别...

  • 初识 Arduino

    介绍 官网 型号 Arduino Uno Arduino Nano Arduino Nano Arduino Na...

  • 2020-04-23

    That is a pre-school child beating a drum ,in sync with a...

  • 历史的天空翻译

    Wars and battles were passed into history. Horns and drum...

  • 攀登英语阅读 21---U的发音[ʌ]

    fun - jump - duck - drum - cup - mushroom - bus - sun - up

  • Shape of You x MPK mini x MainSt

    参考 How To Setup Drum Pads w/ Samples Mainstage MainStage ...

网友评论

    本文标题:arduino 打鼓-DRUM

    本文链接:https://www.haomeiwen.com/subject/funrjctx.html