Skip to content

Commit

Permalink
Release 0.8.5 from Google Code.
Browse files Browse the repository at this point in the history
  • Loading branch information
trash80 committed Jul 26, 2015
1 parent ccfcf69 commit fee719e
Show file tree
Hide file tree
Showing 8 changed files with 635 additions and 153 deletions.
296 changes: 143 additions & 153 deletions Arduinoboy/Arduinoboy.ino
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
/**************************************************************************
* A R D U I N O B O Y *
* *
* Version: 0.3.1 *
* Date: Feb 25 2008 *
* Name: Timothy Lamb *
* Email: [email protected] *
* *
/***************************************************************************
* A R D U I N O B O Y *
* *
* Version: 0.8.5 *
* Date: March 07 2008 *
* Name: Timothy Lamb *
* Email: [email protected] *
* *
* Notes: *
* Pins have changed from the original diagram, expect build *
* instructions to follow here soon: *
* http://code.google.com/p/arduinoboy/ *
* *
* Arduino pin settings: (Layout is final) *
* - 6 LEDS on pins 8 to 13 *
* - Push button on pin 3 (for selecting mode) *
* - MIDI Opto-isolator power on pin 4 *
* - Gameboy Clock line on pin 5 *
* - Gameboy Serial Data input on 6 *
* - Serial Data from gameboy on pin 7 *
* *
* Program Information: *
* LSDJ Slave Mode Midi Note Effects: *
* 48 - C-2 Sends a Sequencer Start Command *
* 49 - C#2 Sends a Sequencer Stop Command *
* 50 - D-2 Toggles Normal Tempo *
* 51 - D#2 Toggles 1/2 Tempo *
* 52 - E-2 Toggles 1/4 Tempo *
* 53 - F-2 Toggles 1/8 Tempo *
* *
* LSDJ Keyboard Mode: *
* 48 - C-2 Mute Pu1 Off/On *
* 49 - C#2 Mute Pu2 Off/On *
* 50 - D-2 Mute Wav Off/On *
* 51 - D#2 Mute Noi Off/On *
* 52 - E-2 Livemode Cue Sequence *
* 53 - F-2 Livemode Cursor Up *
* 54 - F#2 Livemode Cursor Down *
* 55 - G-2 Livemode Cursor Left *
* 56 - G#2 Livemode Cursor Right *
* 57 - A-2 Table Up *
* 58 - A#2 Table Down *
* 59 - B-2 Cue Table *
* 60 - C-3 to C-8 Notes! *
* Prgram Change to select from instrument table *
* *
* Special Thanks to firestARTer for help with *
* keyboard & Midi handling information. *
* *
***************************************************************************/
/***************************************************************************
* *
Expand All @@ -15,69 +56,127 @@
* (at your option) any later version. *
* *
***************************************************************************/

#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 syncEffectsMidiChannel = 8; //midi sync effects, not implemented yet
int mode = 0; //Mode 0: Midi Input to LSDJ Sync, Mode 1: LSDJ MASTER to Midi output
//Mode 0: Midi Input to LSDJ Sync, Mode 1: LSDJ MASTER to Midi output, Mode 2: LSDJ Keyboard
int mode = 0;

//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;

/***************************************************************************
* Lets Assign our Arduino Pins .....
***************************************************************************/
int gbClockLine = 12; // clock out to gameboy
int gbSerialOut = 11; // serial data to gameboy
int gbSerialIn = 10; // serial data from gameboy

int midiInputPower = 2; // power pin for midi input opto-isolator
int pinGBClock = 5; // clock out to gameboy
int pinGBSerialOut = 6; // serial data to gameboy
int pinGBSerialIn = 7; // serial data from gameboy

int pinMidiInputPower = 4; // power pin for midi input opto-isolator

int ledSequencerStop = 8; // stopped light pin
int ledSequencerStart = 9; // start light pin
int pinStatusLed = 13; // Status LED
int pinLeds[] = {12,11,10,9,8}; // LED Pins

int pinButtonMode = 3; //toggle button for selecting the mode

/***************************************************************************
* Memory
***************************************************************************/

int eepromMemoryByte = 0; //Location of where to store settings from mem

/***************************************************************************
* Switches and states
***************************************************************************/
boolean sequencerStarted = false; //Sequencer has Started
boolean midiSyncEffectsHalfTime = false; //Not Implemented yet

boolean midiSyncEffectsTime = false;
boolean midiNoteOnMode =false;
boolean midiNoteOffMode =false;
boolean midiProgramChange=false;
boolean statusLedIsOn =false;
boolean statusLedBlink =false;
/***************************************************************************
* Counter vars
***************************************************************************/
int countLSDJTicks = 0; //for loop int (we need to cycle 8 pulses)
boolean countSyncHalfTime = true; //future feature, Not implemented
int countSyncTime = 0;
int countSyncSteps = 0;
int countGbClockTicks =0;
int countClockPause =0;
int countIncommingMidiByte =0;

int countStatusLedOn =0;

/***************************************************************************
* Inbound Data Placeholders
***************************************************************************/
byte incomingMidiByte; //incomming midi message
byte readgbClockLine;
byte readGbSerialIn;
int incomingMidiData[] = {0, 0, 0};

int incomingMidiNote = 0;
int incomingMidiVel = 0;
byte readToggleMode;

/***************************************************************************
* LSDJ Keyboard mode settings
***************************************************************************/
byte keyboardNotes[] = {0x1A,0x1B,0x22,0x23,0x21,0x2A,0x34,0x32,0x33,0x31,0x3B,0x3A,
0x15,0x1E,0x1D,0x26,0x24,0x2D,0x2E,0x2C,0x36,0x35,0x3D,0x3C};
byte keyboardOctDn = 0x05;
byte keyboardOctUp = 0x06;

byte keyboardInsDn = 0x04;
byte keyboardInsUp = 0x0C;

byte keyboardTblDn = 0x03;
byte keyboardTblUp = 0x0B;

byte keyboardTblCue= 0x29;

byte keyboardMut1 = 0x01;
byte keyboardMut2 = 0x09;
byte keyboardMut3 = 0x78;
byte keyboardMut4 = 0x07;

byte keyboardCurL = 0x6B;
byte keyboardCurR = 0x74;
byte keyboardCurU = 0x75;
byte keyboardCurD = 0x72;
byte keyboardPgUp = 0x7D;
byte keyboardPgDn = 0x7A;
byte keyboardEntr = 0x5A;

int keyboardCurrentOct = 0;
int keyboardCurrentIns = 0;
int keyboardCurrentTbl = 0;

int keyboardLastOct = 0;
int keyboardLastIns = 0;
int keyboardLastTbl = 0;

int keyboardDiff = 0;
int keyboardCount = 0;

void setup() {
/*
Init Pins
*/
pinMode(ledSequencerStop,OUTPUT);
pinMode(ledSequencerStart,OUTPUT);
for(int led=0;led<=5;led++) pinMode(pinLeds[led],OUTPUT);
pinMode(pinStatusLed,OUTPUT);

pinMode(pinButtonMode,INPUT);

if(mode==0) {
pinMode(gbClockLine,OUTPUT);
pinMode(gbSerialOut,OUTPUT);
pinMode(midiInputPower,OUTPUT);
} else if (mode==1) {
pinMode(gbClockLine,INPUT);
pinMode(gbSerialIn,INPUT);
}
pinMode(pinGBClock,OUTPUT);
pinMode(pinGBSerialOut,OUTPUT);
pinMode(pinMidiInputPower,OUTPUT);
pinMode(pinGBSerialIn,INPUT);
/*
Set MIDI Serial Rate
*/
Expand All @@ -86,133 +185,24 @@ void setup() {
/*
Set Pin States
*/
digitalWrite(midiInputPower, HIGH); // turn on the optoisolator
digitalWrite(gbClockLine, HIGH); // gameboy wants a HIGH line
digitalWrite(gbSerialOut, LOW); // no data to send
digitalWrite(ledSequencerStop, HIGH); // then turn it on

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)

/*
Load Settings from EEPROM
*/
if(!forceMode) mode = EEPROM.read(eepromMemoryByte);
showSelectedMode();
}

void loop () {
switch(mode) {
case 0:
modeGameboySlaveSync();
break;
case 1:
modeGameboyMasterSync();
break;
}
}

void modeGameboyMasterSync()
{
while(1){
readgbClockLine = digitalRead(gbClockLine); //Read gameboy's clock line
if(readgbClockLine) {
while(readgbClockLine) {
countClockPause++;
if(sequencerStarted && countClockPause > 8000) {
Serial.print(0xFC, BYTE);
countClockPause = 0;
sequencerStop();
}
readgbClockLine = digitalRead(gbClockLine);
}
countClockPause = 0;
countGbClockTicks++;
if(countGbClockTicks == 8) {
countGbClockTicks=0;
if(!sequencerStarted) {
Serial.print(0xFA, BYTE);
sequencerStart();
}
Serial.print(0xF8, BYTE);
}
}
}
}

void modeGameboySlaveSync()
{
while(1){
if (Serial.available() > 0) {
incomingMidiByte = Serial.read();
switch (incomingMidiByte) {
case 248: // Clock Message Recieved
//send a clock tick out if the sequencer is runn
if(sequencerStarted && midiSyncEffectsHalfTime && countSyncHalfTime
|| sequencerStarted && !midiSyncEffectsHalfTime) {
sendClockTickToLSDJ();
}
if(midiSyncEffectsHalfTime) countSyncHalfTime = !countSyncHalfTime;
break;
case 250: // Transport Start Message
case 251: // Transport Continue Message
sequencerStart();
break;
case 252: // Transport Stop Message
sequencerStop();
break;
default:
if(incomingMidiByte == syncEffectsMidiChannel) {
// This doesnt work yet
// getNote();
}
break;
}
}
}
}

void sequencerStart()
{
digitalWrite(ledSequencerStart, HIGH);
digitalWrite(ledSequencerStop, LOW);
sequencerStarted = true;
}

void sequencerStop()
{
digitalWrite(ledSequencerStart, LOW);
digitalWrite(ledSequencerStop, HIGH);
midiSyncEffectsHalfTime = false;
sequencerStarted = false;
}

void sendClockTickToLSDJ()
{
for(countLSDJTicks=0;countLSDJTicks<8;countLSDJTicks++) {
digitalWrite(gbClockLine,LOW);digitalWrite(gbClockLine,HIGH);
}
}

void getNote()
{
countIncommingMidiByte = 0;
while(countIncommingMidiByte < 2) {
if (Serial.available() > 0) {
countIncommingMidiByte++;
incomingMidiByte = Serial.read();
if(countIncommingMidiByte == 1) {
incomingMidiNote = incomingMidiByte;
} else if(incomingMidiByte > 0) {
switch(incomingMidiNote) {
case 60:
sequencerStart();
break;
case 61:
sequencerStop();
break;
case 62:
midiSyncEffectsHalfTime = !midiSyncEffectsHalfTime;
countSyncHalfTime = true;
break;
}
}
}
}
setMode();
switchMode();
}
Loading

0 comments on commit fee719e

Please sign in to comment.