0

MeggySeq speak
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MeggySeq speak

by jim on Tue May 05, 2009 2:19 am

the MeggySeq project is a great combination of the Meggy Jr RGB and the Wave Shield.

http://www.solipsism.net/2009/03/meggys ... .html#more

the Meggy Jr becomes a step sequencer that sends out numbers 1-8 as
the Wave Shield listens so as to play correspondingly numbered samples.

i have been trying to change what the MeggySeq prints to serial. Instead of the numbers 1 to 8,
i want to send 8 short sets of numbers to a different serial-listening pocket-synth.

MeggySeq 0.0 helps to see what is going on without all the other features of 1.01.

i had to change
Code: Select all | TOGGLE FULL SIZE
Serial.begin(9600//38400
 );
to get the pocket-synth's light to flash with the MeggySeq.
This seems to be where all the serial.print ing seems to happen
Code: Select all | TOGGLE FULL SIZE
 Serial.println(Pattern[CurrentPatt][PlayStep],DEC);

i assume my 8, number-arrays could be sent instead of the 8 numbers.

the pocket-synth is happy with this
Code: Select all | TOGGLE FULL SIZE
void draw(){
  /*  These 2 lines write random sets of bytes to the A_Sid Chip
   The 1st line tells the chip which register to write to ( 28 SID registers available)
   The 2nd line puts a random byte in the register (0-255)
   If wiring & serial connection is correct: You should hear joyful SID chaos */

  port.write(byte(int(random(28))));
  port.write(byte(int(random(255))));
}


i can find the 8 patterns, the 16 steps but not the 8 step-values i want to change.
I can rule out most of the program, only trouble is ruling in what i need to change.


#include <MeggyJr.h>
#include <MeggyJrSimple.h>

/*

Sequencer: 8 patterns of 16 steps

top LEDs display current pattern

screen shows current pattern in 2 rows by 8 steps by 4 dots
each step can play 1-8 (or 0, off)

highlight current step and playing step

L/R to pick step
U/D to change step value (0-8)
A start/stop
B + L/R choose pattern

-- to start, preset simple delay per step
-- later, sync?
-- metronome tick per 1/4 note, 1/8 notes?

-- while playing, print current playing step to serial port. (1 2 3 4, 0 for silence)
(waveshield will play sound based on serial input)

*/

#define STEPCOLOR Dark
#define EDITCOLOR Blue
#define PLAYCOLOR Green
// LONOTE is for 1-4. HINOTE is for 5-8. Yellow and Violet clash.
#define LONOTECOLOR Yellow
#define HINOTECOLOR Violet

const byte up = 4;
const byte down = 8;
const byte left = 16;
const byte right = 32;
const byte B = 1;
const byte A = 2;
byte Alatch = 0;
byte Blatch = 0;
byte Llatch = 0;
byte Rlatch = 0;
byte Ulatch = 0;
byte Dlatch = 0;

uint8_t Pattern[8][16];
uint8_t CurrentPatt=0;
uint8_t EditStep=0;
uint8_t PlayStep=0;
uint8_t i;
uint8_t Running = 0; // are we playing or not?
uint8_t Pulse = 0; // 24 pulses per quarter note for later syncing
uint8_t NewPatt = 1; // did we just change pattern?
uint8_t OldStep = 0;

// 120bpm = 2 beats per second
// 2 beats per second = 48 pulses per second = 24 pulses per 500ms
// 48 pulses per second = roughly 20.8333... ms per pulse
// Let's use 20 ms/pulse for the sake of other processing going on.
uint8_t PulseDelay = 20; // arbitrary for now

void DrawStep(uint8_t Step) {
uint8_t bottomX;
uint8_t bottomY;
uint8_t j;
byte color;
// bottom left is 0,0
// step 0 displays using: 0,4 5 6 7
// step 7 displays using: 7,4 5 6 7
// step 8 displays using: 0,0 1 2 3
// step 15 displays using: 7,0 1 2 3
bottomX=Step % 8;
bottomY=(Step<8)?4:0;

color=STEPCOLOR;
if (Step==EditStep) { color=EDITCOLOR; }
if (Step==PlayStep && Running==1) { color=PLAYCOLOR; }

for(j=0;j<=3;j++) {
if(Pattern[CurrentPatt][Step]==(j+1)) {
// pixel representing what current step is set to
DrawPx(bottomX,bottomY+j,LONOTECOLOR);
} else if (Pattern[CurrentPatt][Step]==(j+5)) {
DrawPx(bottomX,bottomY+j,HINOTECOLOR);
} else {
// pixel representing background color
DrawPx(bottomX,bottomY+j,color);
}

}

}

void setup()
{
MeggyJrSimpleSetup();
Serial.begin(9600
//38400
);
Serial.println("meggyseq");
ClearSlate();
while(CurrentPatt <= 8) {
SetAuxLEDs(1<<CurrentPatt);
delay(150);
CurrentPatt++;
for (i=0; i<=7; i++) {
DrawPx(i,CurrentPatt-1,Blue);
}
DisplaySlate();
}
CurrentPatt=0;
SetAuxLEDs(1<<CurrentPatt);
ClearSlate();
DisplaySlate();


}

void loop()
{
// update playstep
// we only care about 16th notes because we are techno oontz oontz oontz oontz etc.
// 24 pulses per quarter note:
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// + + + +
// update play step
if (Running==1) {
Pulse++;
// Serial.print(".");
if (Pulse > 23) { Pulse=0; }
if (Pulse % 6 == 0) {
OldStep=PlayStep;
PlayStep++;
if (PlayStep==16) { PlayStep=0; }
DrawStep(OldStep);
DrawStep(PlayStep);
Serial.println(Pattern[CurrentPatt][PlayStep],DEC);
}

}

// display current step


// deal with buttons

byte in = Meg.GetButtons();
// code so we can still use == in the if statements below, but still be holding down the A/B buttons
// latch logic gratuitously stolen from Darius
if (!(in& A)) Alatch = 0;
if (!(in& B)) Blatch = 0;
if (!(in& up)) Ulatch = 0;
if (!(in& down)) Dlatch = 0;
if (!(in& left)) Llatch = 0;
if (!(in& right)) Rlatch = 0;
//if (Alatch == 1) in-=2;
//if (Blatch == 1) in-=1;


// if (Button_Right && Button_B) {
if (in==B+right && Blatch==0 && Rlatch==0) {
CurrentPatt++;
if (CurrentPatt > 7) { CurrentPatt = 0; }
NewPatt=1;
Blatch=1;
Rlatch=1;
} else
if (in==B+left && Blatch==0 && Llatch==0) {
if (CurrentPatt==0) {
CurrentPatt=7;
} else {
CurrentPatt--;
}
NewPatt=1;
Blatch=1;
Llatch=1;
}
if (in==right && Rlatch==0) {
OldStep=EditStep;
EditStep++;
DrawStep(OldStep);
if (EditStep > 15) { EditStep = 0; }
DrawStep(EditStep);
Rlatch=1;
}
if (in==left && Llatch==0) {
OldStep=EditStep;
EditStep--;
if (EditStep == 255 ) { EditStep = 15; }
DrawStep(OldStep);
DrawStep(EditStep);
Llatch=1;
}

if (in==up && Ulatch==0) {
Pattern[CurrentPatt][EditStep]++;
if (Pattern[CurrentPatt][EditStep] > 8) { Pattern[CurrentPatt][EditStep] = 8; }
DrawStep(EditStep);
Ulatch=1;
}
if (in==down && Dlatch==0) {
Pattern[CurrentPatt][EditStep]--;
if (Pattern[CurrentPatt][EditStep] == 255 ) { Pattern[CurrentPatt][EditStep] = 0; }
DrawStep(EditStep);
Dlatch=1;
}

if (in==A && Alatch==0) {
if(Running==0) {
Running=1;
OldStep=PlayStep;
DrawStep(PlayStep);
Serial.println(Pattern[CurrentPatt][PlayStep],DEC);
if (PlayStep==16) { PlayStep=0; }
} else {
Running=0;
DrawStep(PlayStep);
PlayStep=0;
}
Alatch=1;
}
// update current pattern
SetAuxLEDs(1<<CurrentPatt);

// draw display

if (NewPatt==1) {
// we just changed step, so draw it all.
for(i=0; i<=15; i++) {
DrawStep(i);
}
NewPatt=0;
}


// Okay, updates made, now we show the screen. Wheee!
DisplaySlate();





delay(PulseDelay);


//Serial.print("running: ");
//Serial.print(Running,DEC);
//Serial.print(" playstep: ");
//Serial.print(PlayStep,DEC);
//Serial.print(" editstep: ");
//Serial.println(EditStep,DEC);

}





may i channel the inspiration i get from you all, into being smart instead of being a smart ass

jim
 
Posts: 106
Joined: Wed Feb 20, 2008 12:15 am
Location: philadelphia

Re: MeggySeq speak

by adafruit on Tue May 05, 2009 12:54 pm

rad! :D

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Please be positive and constructive with your questions and comments.