Skip to content

Commit

Permalink
Release 0.9.8 from Google Code.
Browse files Browse the repository at this point in the history
  • Loading branch information
trash80 committed Jul 26, 2015
1 parent 7ba6f76 commit 2ec6adb
Show file tree
Hide file tree
Showing 9 changed files with 430 additions and 270 deletions.
36 changes: 24 additions & 12 deletions Arduinoboy/Arduinoboy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
***************************************************************************
***************************************************************************
* *
* Version: 0.9.1 *
* Date: March 08 2008 *
* Version: 0.9.8 *
* Date: March 11 2008 *
* Name: Timothy Lamb *
* Email: [email protected] *
* *
Expand Down Expand Up @@ -66,19 +66,21 @@
* *
***************************************************************************/
#include <EEPROM.h>

/***************************************************************************
* Simple User Settings
***************************************************************************/
int syncEffectsMidiChannel = 16; //midi sync effects for lsdj slave mode
int keyboardInstrumentMidiChannel = 16; //midi channel for keyboard instruments in lsdj
int masterNotePositionMidiChannel = 16; //LSDJ in master mode will send its song position on the start button via midi note.
int keyboardInstrumentMidiChannel = 16; //midi channel for keyboard instruments in lsdj.

boolean keyboardCompatabilityMode = true; //Set to true if you are using LSDJ version lower then 2.6, not working right now

//Mode 0: Midi Input to LSDJ Sync
//Mode 1: LSDJ MASTER to Midi output
//Mode 2: LSDJ Keyboard
//Mode 3: Midi Input to Nanoloop
//Mode 4: Pushpin Interface
int mode = 0;
int mode = 0;
int numberOfModes = 4; //Right now there are 4 modes, Might be more in the future

//Enforces the mode above, without reading from memory, use this to force the mode if you dont have a push button setup.
boolean forceMode = false;
Expand Down Expand Up @@ -135,14 +137,17 @@ unsigned int waitClock =0;
byte incomingMidiByte; //incomming midi message
byte readgbClockLine;
byte readGbSerialIn;
byte bit;
int incomingMidiData[] = {0, 0, 0};

int incomingMidiNote = 0;
int incomingMidiVel = 0;
byte readToggleMode;
byte serialWriteBuffer[256];
byte midiDefaultStartOffset;
int writePosition=0;
int readPosition=0;
int lastMode=0; //Stores the last selected mode for leds.
/***************************************************************************
* LSDJ Keyboard mode settings
***************************************************************************/
Expand Down Expand Up @@ -203,21 +208,24 @@ void setup() {
/*
Set MIDI Serial Rate
*/
Serial.begin(31250);
Serial.begin(31250); //31250

/*
Set Pin States
*/
digitalWrite(pinMidiInputPower,HIGH); // turn on the optoisolator
digitalWrite(pinGBClock,HIGH); // gameboy wants a HIGH line
digitalWrite(pinGBSerialOut,LOW); // no data to send
digitalWrite(pinStatusLed,HIGH);
/*
Misc Startup
*/
syncEffectsMidiChannel = 143 + syncEffectsMidiChannel; //set the midi channel to the real number (144 to 159)
keyboardInstrumentMidiChannel = 143 + keyboardInstrumentMidiChannel; //set the midi channel to the real number (144 to 159)
keyboardNoteStart = keyboardStartOctave + 12;
syncEffectsMidiChannel = 143 + syncEffectsMidiChannel; //set the midi channel to the real note-on number (144 to 159)
keyboardInstrumentMidiChannel = 143 + keyboardInstrumentMidiChannel; //set the midi channel to the real note-on number (144 to 159)
masterNotePositionMidiChannel = 143 + masterNotePositionMidiChannel; //set the midi channel to the real note-on number (144 to 159)
keyboardNoteStart = keyboardStartOctave + 12; // Set the octave where the actual notes start (the octave below is for the mutes, cursor, etc)
/*
Assign the keyboard mode command array for the first octave
*/
keyboardCommands[0] = keyboardMut1;
keyboardCommands[1] = keyboardMut2;
keyboardCommands[2] = keyboardMut3;
Expand All @@ -234,9 +242,13 @@ void setup() {
Load Settings from EEPROM
*/
if(!forceMode) mode = EEPROM.read(eepromMemoryByte);
showSelectedMode();
lastMode = mode;
showSelectedMode(); //Light up the LED that shows which mode we are in.
}

/*
Main Loop, which we don't use to be able to isolate each mode into its own setup and loop functions
*/
void loop () {
setMode();
switchMode();
Expand Down
114 changes: 82 additions & 32 deletions Arduinoboy/Mode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,46 @@
* *
***************************************************************************/

/* ***************************************************************************/
/* "Mode" Functions. Deals with changing the setup of arduino. */
/* ***************************************************************************/

/*
setMode will check if the push button is depressed, If it is it will
increment the mode number and make sure its in the
range 0 to 4 by mod (%). It will then write the mode to memory,
set the leds to display the mode, and switch the code over to the
right function.
*/
void setMode()
{
if(digitalRead(pinButtonMode)) {
mode++;
if(mode >= 5) mode = 0;
if(!forceMode) EEPROM.write(eepromMemoryByte, mode);
showSelectedMode();
switchMode();
if(digitalRead(pinButtonMode)) { //if the button is pressed
mode++; //increment the mode number
if(mode > (numberOfModes - 1)) mode=0; //if the mode is greater then 4 it will wrap back to 0
if(!forceMode) EEPROM.write(eepromMemoryByte, mode); //write mode to eeprom if we arnt forcing a mode in the config
showSelectedMode(); //set the LEDS
switchMode(); //switch to the new mode
}
}

/*
showSelectedMode1 turns off the last mode led, turns on the new mode led
and delays for a period of time to reduce jitter behavior from the mode
changing too fast.
*/
void showSelectedMode()
{
for(int led=0;led<=5;led++) digitalWrite(pinLeds[led],LOW);
digitalWrite(pinLeds[lastMode],LOW);
digitalWrite(pinLeds[mode],HIGH);
lastMode = mode;
delay(300);
}

/*
switchMode is only called from setMode. its responsible for
linking the mode number to its corrisponding function,
and then calling that function. function. function.
*/
void switchMode()
{
switch(mode)
Expand All @@ -45,50 +67,78 @@ void switchMode()
case 3:
modeNanoloopSetup();
break;
case 4:
modePushpinSetup();
break;
}
}


/* ***************************************************************************/
/* General Global Functions Used in more then one of the modes */
/* ***************************************************************************/

/*
sequencerStart is called when either LSDJ has started to play in master mode,
or when a MIDI Start or continue command is received in lsdj slave mode.
Basically it just resets some counters we use and sets a "start" flag.
*/

void sequencerStart()
{
sequencerStarted = true;
countSyncPulse = 0;
countSyncTime = 0;
digitalWrite(pinStatusLed,HIGH);
sequencerStarted = true; //Sequencer has started?
countSyncPulse = 0; //Used for status LED, counts 24 ticks (quarter notes)
countSyncTime = 0; //Used to count a custom amount of clock ticks (2/4/8) for sync effects
}

/*
sequencerStop is called when either LSDJ has stopped sending sync commands for
some time in LSDJ Master mode, or when a MIDI Stop command is received in
lsdj slave mode.
Basically it just resets some counters we use and sets the "start" flag to false.
*/
void sequencerStop()
{
midiSyncEffectsTime = false;
sequencerStarted = false;
countSyncPulse = 0;
countSyncTime = 0;
digitalWrite(pinStatusLed,LOW);
midiSyncEffectsTime = false;//Turn off MIDI sync effects in LSDJ slave mode
sequencerStarted = false; //Sequencer has started?
countSyncPulse = 0; //Used for status LED, counts 24 ticks (quarter notes)
countSyncTime = 0; //Used to count a custom amount of clock ticks (2/4/8) for sync effects
}

/*
updateStatusLed should be placed inside of the main loop cycle of a mode function. It counts to a
certain number to delay the action of turning off the status led, so the blink is visible to the human eye. ;)>
I guess this could be called the blinking routine.
*/
void updateStatusLed()
{
if(statusLedIsOn) {
countStatusLedOn++;
if(countStatusLedOn > 3000) {
countStatusLedOn = 0;
digitalWrite(pinStatusLed,LOW);
statusLedIsOn = false;
} else if (statusLedBlink && countStatusLedOn == 1) {
digitalWrite(pinStatusLed,LOW);
} else if (statusLedBlink && countStatusLedOn > 1000) {
statusLedBlink = false;
digitalWrite(pinStatusLed,HIGH);
if(statusLedIsOn) { //is the led on?
countStatusLedOn++; //then increment the counter by 1
if(countStatusLedOn > 3000) { //if the counter is pretty high
countStatusLedOn = 0; //then reset it to zero.
digitalWrite(pinStatusLed,LOW); //and turn off the status led
statusLedIsOn = false; //and set our "is it on?" to false, cause its off now. ;p

} else if (statusLedBlink && countStatusLedOn == 1) { //someone told me to blink, because i was already on
digitalWrite(pinStatusLed,LOW); //so I'll turn off and turn back on later..

} else if (statusLedBlink && countStatusLedOn > 1000) {//Now that I've waited long enough I'll finish my blink.
statusLedBlink = false; //Turn off the issued blink
digitalWrite(pinStatusLed,HIGH); //... and finally turn back on.
}
}
}

/*
statusLedOn is the function to call when we want the status led to blink for us.
all it does is check if its been already asked to turn on, if it has it will set a flag
to make it blink. Either way it will reset the blink timer and turn on the LED
*/
void statusLedOn()
{
if(statusLedIsOn) {
statusLedBlink = true;
statusLedBlink = true; //Make it blink even though its already on
}
statusLedIsOn = true;
countStatusLedOn = 0;
digitalWrite(pinStatusLed,HIGH);
statusLedIsOn = true; //This is the flag the updator function looks for to know if its ok to increment the timer and wait to turn off the led
countStatusLedOn = 0; //Reset the timer
digitalWrite(pinStatusLed,HIGH); //Turn on the led
}
Loading

0 comments on commit 2ec6adb

Please sign in to comment.