Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MIDI.h>
- #include <midi_Defs.h>
- #include <midi_Message.h>
- #include <midi_Namespace.h>
- #include <midi_Settings.h>
- #include <Oscil.h> // oscillator template
- #include <tables/sin2048_int8.h> // sine table for oscillator
- #include <LiquidCrystal.h>
- #include "pitches.h"
- // 2-dimensional array of row pin numbers:
- const int row[8] = {53,51,47,45,41,37,33,29};
- // 2-dimensional array of column pin numbers:
- const int col[8] ={ 22,26,30,34,38,42,46,50 };
- // 2-dimensional array of pixels:
- //int pixels[8][8];
- int currentStep = 0;
- int poti = A1;
- //set beats per minute
- int bpm = 200;
- //set scale
- int changeScale = A2;
- int isPent = 0;
- void setup() {
- Serial.begin(31250);
- // initialize the I/O pins as outputs
- // iterate over the pins:
- for (int thisPin = 0; thisPin < 8; thisPin++) {
- // initialize output and input pins:
- pinMode(col[thisPin], OUTPUT);
- pinMode(row[thisPin], INPUT);
- //switch for scales
- pinMode(changeScale, INPUT);
- //Fields off:
- digitalWrite(col[thisPin], LOW);
- }
- }
- void loop() {
- currentStep = (currentStep + 1) % 8;
- // Aktuelle Spalte unter Strom setzen
- for (int c = 0; c < 8; c++) {
- if (c == currentStep)
- digitalWrite(col[c], HIGH);
- else
- digitalWrite(col[c], LOW);
- }
- // delay von 1-5
- delay(5);
- //Serial.print(currentStep);
- //Serial.print(":\t");
- for (int r = 0; r < 8; r++) {
- int v = digitalRead(row[r]);
- if (v == HIGH) {
- //Serial.print("X");
- playTone(r);
- }
- else {
- //Serial.print(".");
- }
- //pixels[x][y] = v;
- }
- //Serial.println();
- delay(readPoti());
- //audioHook();
- }
- void playTone(int height){
- //play tone
- //1 = highest
- //8 = lowest
- int mytone;
- int miditone;
- isPent = (digitalRead(changeScale));
- //Serial.println(switchState);
- if(isPent == 1){
- //use pentatonic scale
- switch(height){
- case 0:
- mytone = NOTE_C4;
- miditone = 72;
- break;
- case 1:
- mytone = NOTE_D4;
- miditone = 74;
- break;
- case 2:
- mytone = NOTE_E4;
- miditone = 76;
- break;
- case 3:
- mytone = NOTE_G4;
- miditone = 79;
- break;
- case 4:
- mytone = NOTE_A4;
- miditone = 81;
- break;
- case 5:
- mytone = NOTE_C5;
- miditone = 84;
- break;
- case 6:
- mytone = NOTE_D5;
- miditone = 86;
- break;
- case 7:
- mytone = NOTE_E5;
- miditone = 88;
- break;
- }
- }
- else {
- //use major scale
- switch(height){
- case 0:
- mytone = NOTE_C4;
- miditone = 72;
- break;
- case 1:
- mytone = NOTE_D4;
- miditone = 74;
- break;
- case 2:
- mytone = NOTE_E4;
- miditone = 76;
- break;
- case 3:
- mytone = NOTE_F4;
- miditone = 77;
- break;
- case 4:
- mytone = NOTE_G4;
- miditone = 79;
- break;
- case 5:
- mytone = NOTE_A4;
- miditone = 81;
- break;
- case 6:
- mytone = NOTE_B4;
- miditone = 83;
- break;
- case 7:
- mytone = NOTE_C5;
- miditone = 84;
- break;
- }
- }
- tone(52, mytone);
- noteOn(0x90,miditone,0x7f);
- delay(50);
- noTone(52);
- }
- //send midi to output
- void noteOn(int cmd, int pitch, int velocity) {
- Serial.write(cmd);
- Serial.write(pitch);
- Serial.write(velocity);
- }
- //read from poti to set speed
- int readPoti() {
- // set bpm
- int src = analogRead(poti);
- bpm = src;
- //Serial.print(bpm);
- //optional: transform to bmp
- return bpm;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement