Close
0%
0%

Beat - Pad

Portable and Programmable Beat - Pad

KaiKai
Similar projects worth following
167 views
0 followers
Drum machine!

Embedded-Systems/beats.ino at main · stackedflows/Embedded-Systems (github.com)

#include <Keypad.h>

// define the max number of beats the user can create and loop
const int max_beats = 1000;

// speaker output pins
const int sound_pin_0 = 12;
const int sound_pin_1 = 13;

// sound variables
int tones[] = {100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850};

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

//define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'0','1','2','3'},
  {'4','5','6','7'},
  {'8','9','A','B'},
  {'C','D','E','F'}
};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

// array records the current beat saved to the device
char current_beat[max_beats];

// we assign key S16 -> '8' for record functionality, S15 -> 'C' for playback
bool record = false;

// keeps track of how many beats are currently in memory for the current track: must be <= max_beats
int press_count = 0;

void setup(){
  Serial.begin(9600);
  // declare sound pins as output
  pinMode(sound_pin_0, OUTPUT);
  pinMode(sound_pin_1, OUTPUT);

  // initialise beats
  for(int i = 0; i < max_beats; i++){
    current_beat[i] = 0;
  }
}


void loop(){
  // listen for keydown
  char customKey = customKeypad.getKey();
  
  // act on keydown
  for(int i = 0; i < 4; i++){
    for(int ii = 0; ii < 4; ii++){
      if(customKey == hexaKeys[i][ii]){
        // handle record setting 
        if(customKey == 'C'){
          record = !record;
        }
        // handle playback
        else if (customKey == '8'){
          playback();
        }
        else{
          // plays note no matter what
          sound(sound_pin_0, tones[i + ii]);
          sound(sound_pin_1, tones[i + ii]);
          // only records not if these conditions are met
          if(record && press_count < max_beats){
            current_beat[press_count] = i + ii;
            press_count++;
          }
        }
      }
    }
  }
}

// sound creation
void sound(int pin, int tones){
  tone(pin, tones);
  delay(200);
  noTone(pin);
}

// creates accurate playback
void playback(){
  int user_beats[press_count];
  for(int i = 0; i < press_count; i++){
    user_beats[i] = current_beat[i];
  }
  for(int i = 0; i < press_count; i++){
    sound(sound_pin_0, tones[user_beats[i]]);
    sound(sound_pin_1, tones[user_beats[i]]);
  }
}

soundOfK03.ino

Enables user programming

ino - 2.67 kB - 05/06/2021 at 20:05

Download

  • 1 × Sparkfun RedBoard (Arduino)
  • 1 × 16x16 button matrix with 8 male connectors
  • 2 × speakers with 2 female connectors
  • 2 × breadboards (14 x 30, 16 x 10)
  • 25 × male - male wires

View all 6 components

View all 2 project logs

  • 1
    Basic Components
  • 2
    First Steps
  • 3
    Circuit Connectors

View all 4 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates