hello arduino team, this is my first forum post. I have only started to try coding recently because of this community and am grateful for any assistance anyone can offer.
I have began coding a polyphonic "note" (LED) sequencer. simple concept I hope
Basic setup so far
8 step
4 part
input : ps2 keyboard
output : ascii terminal characters + digital pin triggers analog drum triggers or others possibly arpeggios for Mozzi synth
I would rather not use the delay function.
/*
PS2 KEYBOARD -> ASCII Terminal + pinMode output trigger////////////////////////////////////////// * music note Step Sequencer * //////////////////////////////////////////////////
THIS IS THE PROGRAM I "CUT MY TEETH" ON PLEASE HELP ME ADD A BPM METRONOME AND REMOVE THE delays
*/
#include <PS2Keyboard.h>
const int DataPin = 2;
const int IRQpin = 3;
int playStop = 8;
PS2Keyboard keyboard;
int time = 300;
int kick = 4;
int snare = 7;
int hat = 8;
char drum_1[9] = { '-', '-', '-', '-', '-', '-', '-', '-', } ;
char drum_2[9] = { '-', '-', '-', '-', '-', '-', '-', '-', } ;
char drum_3[9] = { '-', '-', '-', '-', '-', '-', '-', '-', } ;
void setup()
{
delay(1000);
keyboard.begin(DataPin, IRQpin);
Serial.begin(9600);
pinMode(kick,OUTPUT);
pinMode(snare,OUTPUT);
}
void loop()
{
if ( playStop == 0){
play();
} else if (keyboard.available())
{
char c = keyboard.read();
if (c == PS2_ENTER & playStop == 8){
playStop = 0;
//play();
}
}
}
void play()
{
for (int i = playStop; i < 8; i++)
{
Serial.print (drum_1[i] );
Serial.print (drum_2[i]);
Serial.println (drum_3[i]);
digitalWrite (kick, LOW);
delay(time);
if (keyboard.available())
{
char c = keyboard.read();
{
if (c == PS2_ENTER & playStop == 0){
playStop = 8;
i = 8;
/* This is where I began to tiker with the tempo/metronome I eventuall want to use a 8 or 4 count modulo operator for BPM
also I WOULD RATHER NOT USE THE DELAY function so other actions can take place.
} else if (c == '-' & time <= 300) {
time + 20 ;
} else if (c == '=' & time >= 100) {
time - 20 ;
*/
} else if (c == '1' & drum_1[0] == '-' ) {
drum_1[0] = 'K';
} else if (c == '1' & drum_1[0] == 'K' ) {
drum_1[0] = '-';
} else if (c == 'q' & drum_2[0] == '-' ) {
drum_2[0] = 'S';
} else if (c == 'q' & drum_2[0] == 'S' ) {
drum_2[0] = '-';
} else if (c == 'a' & drum_3[0] == '-' ) {
drum_3[0] = 'H';
} else if (c == 'a' & drum_3[0] == 'H' ) {
drum_3[0] = '-';
} else if (c == '2' & drum_1[1] == '-' ) {
drum_1[1] = 'K';
} else if (c == '2' & drum_1[1] == 'K' ) {
drum_1[1] = '-';
} else if (c == 'w' & drum_2[1] == '-' ) {
drum_2[1] = 'S';
} else if (c == 'w' & drum_2[1] == 'S' ) {
drum_2[1] = '-';
} else if (c == 's' & drum_3[1] == '-' ) {
drum_3[1] = 'H';
} else if (c == 's' & drum_3[1] == 'H' ) {
drum_3[1] = '-';
} else if (c == '3' & drum_1[2] == '-') {
drum_1[2] = 'K';
} else if (c == '3' & drum_1[2] == 'K') {
drum_1[2] = '-';
} else if (c == 'e' & drum_2[2] == '-') {
drum_2[2] = 'S';
} else if (c == 'e' & drum_2[2] == 'S') {
drum_2[2] = '-';
} else if (c == 'd' & drum_3[2] == '-') {
drum_3[2] = 'H';
} else if (c == 'd' & drum_3[2] == 'H') {
drum_3[2] = '-';
} else if (c == '4' & drum_1[3] == '-' ) {
drum_1[3] = 'K';
} else if (c == '4' & drum_1[3] == 'K' ) {
drum_1[3] = '-';
} else if (c == 'r' & drum_2[3] == '-' ) {
drum_2[3] = 'S';
} else if (c == 'r' & drum_2[3] == 'S' ) {
drum_2[3] = '-';
} else if (c == 'f' & drum_3[3] == '-' ) {
drum_3[3] = 'H';
} else if (c == 'f' & drum_3[3] == 'H' ) {
drum_3[3] = '-';
} else if (c == '5' & drum_1[4] == '-') {
drum_1[4] = 'K';
} else if (c == '5' & drum_1[4] == 'K') {
drum_1[4] = '-';
} else if (c == 't' & drum_2[4] == '-') {
drum_2[4] = 'S';
} else if (c == 't' & drum_2[4] == 'S') {
drum_2[4] = '-';
} else if (c == 'g' & drum_3[4] == '-') {
drum_3[4] = 'H';
} else if (c == 'g' & drum_3[4] == 'H') {
drum_3[4] = '-';
} else if (c == '6' & drum_1[5] == '-' ) {
drum_1[5] = 'K';
} else if (c == '6' & drum_1[5] == 'K' ) {
drum_1[5] = '-';
} else if (c == 'y' & drum_2[5] == '-' ) {
drum_2[5] = 'S';
} else if (c == 'y' & drum_2[5] == 'S' ) {
drum_2[5] = '-';
} else if (c == 'h' & drum_3[5] == '-' ) {
drum_3[5] = 'H';
} else if (c == 'h' & drum_3[5] == 'H' ) {
drum_3[5] = '-';
} else if (c == '7' & drum_1[6] == '-') {
drum_1[6] = 'K';
} else if (c == '7' & drum_1[6] == 'K') {
drum_1[6] = '-';
} else if (c == 'u' & drum_2[6] == '-') {
drum_2[6] = 'S';
} else if (c == 'u' & drum_2[6] == 'S') {
drum_2[6] = '-';
} else if (c == 'j' & drum_3[6] == '-') {
drum_3[6] = 'H';
} else if (c == 'j' & drum_3[6] == 'H') {
drum_3[6] = '-';
} else if (c == '8' & drum_1[7] == '-') {
drum_1[7] = 'K';
} else if (c == '8' & drum_1[7] == 'K') {
drum_1[7] = '-';
} else if (c == 'i' & drum_2[7] == '-') {
drum_2[7] = 'S';
} else if (c == 'i' & drum_2[7] == 'S') {
drum_2[7] = '-';
} else if (c == 'k' & drum_3[7] == '-') {
drum_3[7] = 'H';
} else if (c == 'k' & drum_3[7] == 'H') {
drum_3[7] = '-';
/* This is where I began trying to add the digital pinsMode ouputs pulse triggers. I realized that there must be a more appropriate way and the delays are not the best method please help
// thanksAlot[] {"arduinoTeam"};
if (drum_1[i] == 'K') {
digitalWrite(kick,HIGH);
delay (12);
} else if (drum_1[i] == '-') {
digitalWrite(kick,LOW);
delay (12);
if (drum_2[i] == 'S') {
digitalWrite(snare,HIGH);
delay (12);
digitalWrite(kick,LOW);
} else if (drum_2[i] == '-') {
digitalWrite(snare,LOW);
delay (12);
if (drum_3[i] == 'H') {
digitalWrite(hat,HIGH);
delay (12);
digitalWrite(kick,LOW);
} else if (drum_3[i] == '-') {
digitalWrite(hat,LOW);
delay (12);
} else if (drum_3[i] == 'H') {
digitalWrite(kick,HIGH);
delay (12);
digitalWrite(kick,LOW);
*/
}
}
}
}
}