//-----------------------------------------------------------------------------
//-------- Copyright (c)2003-2013. All Rights Reserved. -----------------------
//-----------------------------------------------------------------------------
// file implementing MIDI controller 'Numark Mixdeck Express' V1.1
// author: Brandon James for DEX 2.61+
//----------------------------------------------------------------------------- 
function getLanguageVersion()
{
	return 1;// do not modify this, this should be 1 for all scripts
}
//----------------------------------------------------------------------------- 
function getFileVersion()
{
	return 1;// update this as needed
}
//----------------------------------------------------------------------------- 
// return a user friendly name for the controller supported
function getControllerUserFriendlyName()
{
	return "Mixdeck Express";
}
//----------------------------------------------------------------------------- 
// return the communication type that the controller supports 
// this can be either 'midi' or 'hid' (please return only one of them in case the controller supports both)
function getControllerType()
{
	return 'midi';
}
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
// preferred way to identify the controller (using the USB device VID and PID -- vendor and product id)
// return false if the controller does not support this kind of identification
// osId -- 0 Windows; 1 MacOSX; 2 Linux; -1 unknown
function getSupportedHidDeviceVID(osId)
{
	return false;
}
//----------------------------------------------------------------------------- 
function getSupportedHidDevicePID(osId)
{
	return false;
}
//----------------------------------------------------------------------------- 
// this is NOT the preferred way to identify the controller but you should use
// it if the controller does not support standard USB VID and PID identification
// return false if the controller does not support this kind of identification
// osId -- 0 Windows; 1 MacOSX; 2 Linux; -1 unknown
function getSupportedHidDeviceName(osId)
{
	return false;
}
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
//----------------------------------------------------------------------------- 
// preferred way to identify the controller (if it supports MIDI SysEx)
// return false if the controller does not support this kind of identification
function getSupportedMidiSysExIdString(osId)
{
	// sysex response to 'F0 7E 7F 06 01 F7' (identification request sysex)
	// please note that the response contains 5 bytes in hex format containing
	// the Manufacturer ID (3 bytes) and Model Number (2 bytes)
	// ATTN: the returned value should omit the standard 'F0 7E 00 06 02' message start
	//if(osId==1) return false;
	
	if(osId==0) return false;
	if(osId==1) return false;
	//return "00013F420019";
	// 00  F0 7E 00 06 02 00 01 3F  42 00 19 00 01 00 06 00 10  00 00 00 00 00 4E 01 01  03 00 01 02 05 01 01 00 20  00 08 05 02 F7

	

}
//----------------------------------------------------------------------------- 
// this is NOT the preferred way to identify the controller but you should use
// it if the controller does not support standard MIDI SysEx identification
// return false if the controller does not support this kind of identification
// osId -- 0 Windows; 1 MacOSX; 2 Linux; -1 unknown
function getSupportedMidiDeviceNameForInput(osId)
{
	if(osId==0) return "MixDeck Express";
	if(osId==1) return "MixDeck Express";  
	//return false;
}
//----------------------------------------------------------------------------- 
function getSupportedMidiDeviceNameForOutput(osId)
{
	if(osId==0) return "MixDeck Express";
	if(osId==1) return "MixDeck Express";  
	//return false;
}
//----------------------------------------------------------------------------- 
// script dependent functions


//----------------------------------------------------------------------------- 
// some variables necessary only for this particular script
var loopingInBlinkLed=[-1,-1];// -1 means disabled
var jogWheelsInScratchMode=[0,0];
var timeStatus=[0,0];// 0 means elapsed, 1 remained
var bpm=[0,0]; //BPM
var searchMode=[0,0,];
//----------------------------------------------------------------------------- 
// this is called when the controller is initialized and the control is passed to this script
// use this to initialize any variables you might need, the controller' leds, etc
// uniqueId is a unique integer between 0..15 that is guaranteed not to change for 
// a certain opened controller -- please note that there can be many controllers
// of the same type in use at the same time ! Use uniqueId to identify between them
function controllerInit(uniqueId)
{
	debug('controllerInit Mixdeck_express ['+uniqueId+']');// this outputs a string to DebugView app on Win
	callSendAllNotifications(uniqueId, true);// send all notifications to the controller (so that we don't have to manually init all leds/lcd screens)
	for(var i=0; i<2; i++)
	{
		sendMidi(uniqueId,0x90,i,0x47,0x7F); // elapsed LCD (var is initiated 0
		sendMidi(uniqueId,0x90,i,0x4D,(getValue('play', i) ? 0x7F : 0x00));// play LCD
		sendMidi(uniqueId,0x90,i,0x4B,(getValue('cue', i) ? 0x7F : 0x00)); //cue LCD
		sendMidi(uniqueId,0x90,i,0x57,(getValue('keyLock', i) ? 0x7F : 0x00));// MT LCD	
		sendMidi(uniqueId,0xB0,i,0x24,0x01); // m/c/f/icons
		sendMidi(uniqueId,0xB0,i,0x31,0X01); //time digit on
		sendMidi(uniqueId,0xB0,i,0x32,0x01); //BPM digit on
		sendMidi(uniqueId,0x90,i,0x51,0X7F); //BPM icon on
		sendMidi(uniqueId,0xB0,i,0x34,0X01); //pitch digit on
		sendMidi(uniqueId,0xB0,i,0x37,0X01); //pitch decimal on
		sendMidi(uniqueId,0x90,i,0x52,0X7F); //pitch icon on
		sendMidi(uniqueId,0x90,i,0x3F,0x00); // scratch
		sendMidi(uniqueId,0x90,i,0x40,0x00); // search
		
			var name = 'PCDJ';
			var nameLen = Math.min(9, name.length);
			if((nameLen>0)&&(lastTextDisplayed[i] != name))
			{
				//debug('name='+name+' nameLen='+nameLen);
				var sysexData = new Array(10+nameLen);
				sysexData[0] = 0xF0;
				sysexData[1] = 0x00;
				sysexData[2] = 0x01;
				sysexData[3] = 0x3F;
				sysexData[4] = 0x42;
				sysexData[5] = (i==0)?0x01:0x20;
				sysexData[6] = Math.floor(nameLen/256);// most significant N
				sysexData[7] = nameLen%256;// least significant N
				for(var j=0; j<nameLen; j++) sysexData[8+j] = name.charCodeAt(j);// data
				sysexData[8+nameLen] = 0xF7;
				// send the sysex
				sendMidiSysEx(uniqueId, sysexData, 8+nameLen+1);
				lastTextDisplayed[i] = name;
			}
	/*	
		sendMidi(uniqueId,0x90,i,0x7F,0x00); //all LCD's off
		sendMidi(uniqueId,0x90,i,0x33,(getValue('play', i) ? 0x7F : 0x00));// play-pause		
		sendMidi(uniqueId,0x90,i,0x31,(getValue('cue', i) ? 0x7F : 0x00)); //cue
		sendMidi(uniqueId,0x90,i,0x4C,0x00); //Pause LCD
		sendMidi(uniqueId,0x90,i,0x3C,(getValue('pitchIs0', i) ? 0x7F : 0x00)); //pitch = 0
		sendMidi(uniqueId,0x90,i,0x34,(getValue('loopIn', i) ? 0x7F : 0x00));// Loop In 	off
		sendMidi(uniqueId,0x90,i,0x35,0x00);// Loop Out off
		sendMidi(uniqueId,0x90,i,0x36,0x00);// Reloop off
		sendMidi(uniqueId,0x90,i,0x37,(getValue('brake', i) ? 0x7F : 0x00)); // brake
		sendMidi(uniqueId,0x90,i,0x38,(getValue('reverse', i) ? 0x7F : 0x00)); // reverse
		sendMidi(uniqueId,0x90,i,0x3F,0x00); // scratch
		sendMidi(uniqueId,0xB0,i,0x21,0x7F); //pitch led's all on still switched
		
		//bpm and pitch digits 0x2x = 1-127 / 0x4x = +128
		//sendMidi(uniqueId,0xB0,i,0x4D,1);
		//sendMidi(uniqueId,0xB0,i,0x21,0x02);
		
	*/	
		call('sleep', 10);// delay for 10ms to allow the MIDI out buffer to flush

	}
}
//----------------------------------------------------------------------------- 
// called just before the controller will be deinitialized and the control will go away from the script
// use to power off any powered leds, etc
function controllerDeinit(uniqueId)
{
	debug('controllerDeinit Mixdeck_express ['+uniqueId+']');
	callSendAllNotifications(uniqueId, false);// send all notifications to the controller (so that we don't have to manually init all leds/lcd screens)
	
	for(var i=0; i<2; i++)
	{
		sendMidi(uniqueId,0xB0,i,0x21,0x00); //pitch change LED off
		sendMidi(uniqueId,0xB0,i,0x25,0x00); //progress bar lcd off
		sendMidi(uniqueId,0x90,i,0x4D,0x00); //play LCD
		sendMidi(uniqueId,0x90,i,0x4B,0x00); //cue LCD
		sendMidi(uniqueId,0x90,i,0x4C,0x00); //pause LCD
		sendMidi(uniqueId,0x90,i,0x57,0x00); // MT LCD
		sendMidi(uniqueId,0x90,i,0x7F,0x00); //all LCD's off
		sendMidi(uniqueId,0x90,i,0x7E,0x00); //all LED's off
		sendMidi(uniqueId,0x90,i,0x47,0x00); // elapsed LCD off
		sendMidi(uniqueId,0x90,i,0x4A,0x00); // Remain LCD off
		sendMidi(uniqueId,0xB0,i,0x24,0x00); // m/c/f/icons
		sendMidi(uniqueId,0xB0,i,0x31,0X00); //time off
		sendMidi(uniqueId,0xB0,i,0x32,0X00); //BPM digit off
		sendMidi(uniqueId,0x90,i,0x51,0X00); //BPM icon off
		sendMidi(uniqueId,0xB0,i,0x34,0X00); //pitch digit off
		sendMidi(uniqueId,0xB0,i,0x37,0X00); //pitch decimal off
		sendMidi(uniqueId,0x90,i,0x52,0X00); //pitch icon off
		sendMidi(uniqueId,0x90,i,0x3F,0x00); // scratch
		sendMidi(uniqueId,0x90,i,0x40,0x00); // search
		sendMidi(uniqueId,0x90,i,0x7E,0x00); // all led off
		
			var name = 'Goodbye';
			var nameLen = Math.min(9, name.length);
			if((nameLen>0)&&(lastTextDisplayed[i] != name))
			{
				//debug('name='+name+' nameLen='+nameLen);
				var sysexData = new Array(10+nameLen);
				sysexData[0] = 0xF0;
				sysexData[1] = 0x00;
				sysexData[2] = 0x01;
				sysexData[3] = 0x3F;
				sysexData[4] = 0x42;
				sysexData[5] = (i==0)?0x01:0x20;
				sysexData[6] = Math.floor(nameLen/256);// most significant N
				sysexData[7] = nameLen%256;// least significant N
				for(var j=0; j<nameLen; j++) sysexData[8+j] = name.charCodeAt(j);// data
				sysexData[8+nameLen] = 0xF7;
				// send the sysex
				sendMidiSysEx(uniqueId, sysexData, 8+nameLen+1);
				lastTextDisplayed[i] = name;
			}
		//sendMidiSysEx(uniqueId,0x00 0xF0 0x00 0x01 0x3F 0x42 0x01 0x00 0x09  0x20 0x47 0x6F 0x6F 0x64 0x20 0x42 0x79 0x10 0x65 0xF7);

/*		sendMidi(uniqueId,0x90,i,0x33,0x00); //play
		sendMidi(uniqueId,0x90,i,0x31,0x00); //cue
		sendMidi(uniqueId,0x90,i,0x34,0x00); // Loop In 		
		sendMidi(uniqueId,0x90,i,0x35,0x00); // Loop Out
		sendMidi(uniqueId,0x90,i,0x36,0x00); // Reloop
		sendMidi(uniqueId,0x90,i,0x3C,0x00); // pitch 0
		sendMidi(uniqueId,0x90,i,0x37,0x00); // brake
		sendMidi(uniqueId,0x90,i,0x38,0x00); // reverse
		sendMidi(uniqueId,0x90,i,0x3F,0x00); // scratch
		sendMidi(uniqueId,0xB0,i,0x21,0x00); //ptich change LED
		
*/		
		call('sleep', 10);// delay for 10ms to allow the MIDI out buffer to flush
	

	}
}


//----------------------------------------------------------------------------- 
// this is your main target function to implement the controller -- this is called 
// for each and every MIDI message that comes from the controller itself
// return true if the message was processed by the script and false to let it 
// pass thru the software (eg. so it can be assigned by the user using the LEARN function)
function messageReceived(uniqueId,status,channel,data1,data2)
{
	var messageNotProcessed=false;
	switch(status)
	{
	//-----------------------------------------------
	// controllers: sliders, knobs, jog-wheels, encoders ('moving' things)
	case 0xB0:
		switch(data1)
		{
		// global
		case 0x21: call('lbMoveCursor', data2==0x01 ? 1:-1); break; //library curser up down		

		case 0x22: // params: (deck, increment, total positions per complete revolution) 
			var val1 = (data2>0x40 ? data2-0x80 : data2); 
			if(searchMode[channel]==0)
			{
				// normal mode (pitch bend / scratch)
				if(jogWheelsInScratchMode[channel]) call('scratchDeckJW', channel, val1, 600);else call('moveDeckJogWheel', channel, val1, 600);
			}else
			{
				// search mode (search left/right)
				call('searchDeckJW', channel, val1, 600);
			}
			break;
			
		// decks

				

		default: messageNotProcessed = true;
		}
		break;
	//-----------------------------------------------
	// note on/off: buttons, switches ('pressing' things)
	case 0xE0: call('setDeckPitch', channel, 0x7F-data2); break; //pitch slider
	case 0x80:
	case 0x90:
		//if(status==0x90) data2 = 0x7F;
		if(status==0x80) data2 = 0;
		switch(data1)
		{
		// global
		case 0x4B: if(data2>0x3F) call('lbToggleSelect', data2); break;


		
		// decks
		

		case 0x3F: call('deckCue', channel, data2); break; //play pause 1/2
		case 0x3D: call('deckPlayPause', channel, data2); break; //play pause 1/2		
		case 0x4E: call('deckLBLoad', channel, data2); break; //load deck
		case 0x4F: call('deckTapBpm', channel, data2); break; //tap bpm
		case 0x37: call('deckLoopInEnd', channel, data2); break; //loop in/end
		case 0x36: if(!getValue('looping', channel)) call('deckLoopInEnd', channel, data2);else call('deckLoopExit', channel, data2); break; //Loop //loop end or exit
		case 0x35: call('deckLoopReloop', channel, data2); break //reloop
		
		case 0x48: // simulate a fast press-release for both note on and note off
				   call('deckReverse', channel, 0x7F);
    			   call('deckReverse', channel, 0x00);
    			   break;
				
		case 0x4D: call('deckBrake', channel, data2); break; //brake
		case 0x3B: call('deckBendDown', channel, data2); break; //pitch bend down
		case 0x3A: call('deckBendUp', channel, data2); break; //pitch bend up
		
					// pitch range cycle/toggle
		case 0x3C:
			// 1 = 4%; 2 = 8%; 3 = 16%; 4 = 24%; 5 = 32%; 6 = 50%;
			if(data2>0x3F)
			{
				var currentPitchRange = getValue('pitchRange');// we only want 1, 3, 5
				switch(currentPitchRange)
				{
				case 1:
				case 2: currentPitchRange = 3; break;
				case 3:
				case 4: currentPitchRange = 5; break;
				case 5:
				case 6: currentPitchRange = 1; break;
				}
				call('setPitchRange', currentPitchRange);
			}
			break;
			
		case 0x44: if(data2>0x3F) 
						{
						searchMode[channel] = 0
						jogWheelsInScratchMode[channel] = (jogWheelsInScratchMode[channel]+1) % 2; sendMidi(uniqueId,0x90,channel,0x3F,(jogWheelsInScratchMode[channel] ? 0x7F : 0x00));
						sendMidi(uniqueId,0x90,channel,0x40,(searchMode[channel] ? 0x7F : 0x00)); 
						}
						break;
		case 0x50: if(jogWheelsInScratchMode[channel]) call('holdDeckJogWheel', channel, data2); break
		case 0x4A: 
			if(data2>0x3F) 
			{
				timeStatus[channel] = (timeStatus[channel]+1)%2;
				sendMidi(uniqueId,0x90,channel,0x4A,(timeStatus[channel]==1 ? 0x7F : 0x00)); //remain lcd
				sendMidi(uniqueId,0x90,channel,0x47,(timeStatus[channel]==0 ? 0x7F : 0x00)); //elapsed lcd
			}
			break;

			case 0x45: 
				if(data2>0x3F) 
					{
					jogWheelsInScratchMode[channel] = 0
					searchMode[channel] = (searchMode[channel]+1)%2;
					sendMidi(uniqueId,0x90,channel,0x40,(searchMode[channel] ? 0x7F : 0x00));
					sendMidi(uniqueId,0x90,channel,0x3F,(jogWheelsInScratchMode[channel] ? 0x7F : 0x00));
					}
				break;

		default: messageNotProcessed = true;
		}
		break;
	//-----------------------------------------------
	default: messageNotProcessed = true;
	}
	if(messageNotProcessed) debug('messageReceived ['+uniqueId+'] - status:'+status+' channel:'+channel+' data1:'+data1+' data2:'+data2);
	return !messageNotProcessed;
}
//----------------------------------------------------------------------------- 
// this is called by the software whenever something important changes (eg. play status, song changed, etc)
// depending on the notification type it may refer to a global event (deck is -1) or a specific deck (deck >= 0)
// and can contain any/all of the parameters: param 1 is an integer, param 2 is a float, param 3 is a string
function notificationReceived(uniqueId,name,deck,param1,param2,param3)
{
	//debug('notif ['+uniqueId+'] name='+name + ' deck='+deck + ' p1(int)='+param1 + ' p2(float)='+param2 + ' p3(str)='+param3);
	if(deck<2)
	{
		if(name=='cue') 		{
								 sendMidi(uniqueId,0x90,deck,0x31,(param1 ? 0x7F : 0x00)); // cue
								 sendMidi(uniqueId,0x90,deck,0x4B,(param1 ? 0x7F : 0x00)); // cue LCD
								 sendMidi(uniqueId,0x90,deck,0x4C,(param1 ? 0x00 : 0x00)); //pause LCD off
								 }
		if(name=='play') 		{
								 sendMidi(uniqueId,0x90,deck,0x33,(param1 ? 0x7F : 0x00)); //play
								 sendMidi(uniqueId,0x90,deck,0x4D,(param1 ? 0x7F : 0x00)); //play LCD
								 sendMidi(uniqueId,0x90,deck,0x4C,(param1 ? 0x00 : 0x7F)); //pause LCD on / off
								 }
		if(name=='reverse') 	 sendMidi(uniqueId,0x90,deck,0x37,(param1 ? 0x7F : 0x00)); //reverse
		if(name=='brake') 	 	 sendMidi(uniqueId,0x90,deck,0x38,(param1 ? 0x7F : 0x00)); //brake
		if(name=='pitchIs0')	 sendMidi(uniqueId,0x90,deck,0x3C,(param1 ? 0x7F : 0x00)); //pitch =0
		if(name=='keyLock')	     sendMidi(uniqueId,0x90,deck,0x57,(param1 ? 0x7F : 0x00)); //key lock LCD
		if(name=='loopIn')
			{
			sendMidi(uniqueId,0x90,deck,0x34,(param1 ? 0x7F : 0x00));// Loop In (on or off)
			// activate blinking for the LoopIn led (so the user knows to press it again)
			if(param1) loopingInBlinkLed[deck] = 0;else loopingInBlinkLed[deck] = -1;
			}
		if(name=='looping')
			{
				sendMidi(uniqueId,0x90,deck,0x34,0x00);// Loop In (off)		
				sendMidi(uniqueId,0x90,deck,0x35,(param1 ? 0x7F : 0x00));// Loop Out (on or off)
				sendMidi(uniqueId,0x90,deck,0x36,(param1 ? 0x7F : 0x00));// Reloop (on or off)
				sendMidi(uniqueId,0x90,deck,0x58,(param1 ? 0x7F : 0x00));// Reloop LCD (on or off)
			}
		if(name=='pitchRange')
		{
				if(param1==1) 
					{
						sendMidi(uniqueId,0xB0,0,0x21,1);
						sendMidi(uniqueId,0xB0,1,0x21,1);
					}
				if(param1==3) 
					{	
						sendMidi(uniqueId,0xB0,0,0x21,2);
				 		sendMidi(uniqueId,0xB0,1,0x21,2);
				 	}
				if(param1==5) 
					{
						sendMidi(uniqueId,0xB0,0,0x21,3);
						sendMidi(uniqueId,0xB0,1,0x21,3);
					}
		}
	}
}
//----------------------------------------------------------------------------- 
// value is a float (seconds)
function showTimeValue(uniqueId, deck, value)
{
	// split time in min/sec/100ths
	var sec = Math.floor(value);
	var hsec = Math.floor((value - sec)*100);
	var min = Math.floor(sec/60);
     sec = sec % 60;
	//debug('showTimeValue ['+uniqueId+'] = '+min+':'+sec+'.'+hsec);
	// display
	sendMidi(uniqueId, 0xB0, deck, 0x29, min);
	sendMidi(uniqueId, 0xB0, deck, 0x2A, sec);
	sendMidi(uniqueId, 0xB0, deck, 0x2B, hsec);
}
//----------------------------------------------------------------------------- 
var timer1=0;
var lastTextDisplayed=['','','',''];
// this is called from time to time by the software (several times per second)
// (it is guaranteed that 'timerTick' will get executed ALWAYS right after notificationReceived)
function timerTick(uniqueId)
{
	//debug('timerTick ['+uniqueId+']');
	timer1++; if(timer1>15) timer1 = 0;

	for(var i=0; i<2; i++)
	{
		var timeElapsed = getValue('timeElapsed', i);// float seconds
		var timeRemain = getValue('timeRemain', i);// float seconds
		var bpm = getValue('currentBpm', i);// float bpm
		var pitch = getValue('pitch', i);// pitch (100th of percents)
		if(timer1 % 3 == 0)
		{
			// progress bar
			if(timeStatus[i]==0)
			{
				// elapsed
				var tempTime = timeElapsed / (timeElapsed+timeRemain);// this will result in [0..1]
				sendMidi(uniqueId,0xB0,i,0x25, 1 + tempTime*19);// 1..20
				showTimeValue(uniqueId, i, timeElapsed);
			}else
			{
				// remaining
				var tempTime = 1.0 - (timeRemain / (timeElapsed+timeRemain));// this will result in [1..0]
				sendMidi(uniqueId,0xB0,i,0x25, 21 + tempTime*19);// 21..40
				showTimeValue(uniqueId, i, timeRemain);
			}
			// BPM value
			sendMidi(uniqueId,0xB0,i,0x2C,bpm%128);
			sendMidi(uniqueId,0xB0,i,0x4C,Math.floor(bpm/128));
			// pitch value
			if(pitch>=0)
			{
				sendMidi(uniqueId,0xB0,i,0x2D,pitch%128);
				sendMidi(uniqueId,0xB0,i,0x4D,Math.floor(pitch/128));
			}else
			{
			    var tmpPitch = 8192 + pitch;
				sendMidi(uniqueId,0xB0,i,0x2D, tmpPitch%128);
				sendMidi(uniqueId,0xB0,i,0x4D, 64 + Math.floor(tmpPitch/128));
			}
			// artist-title
			var name = getValue('artist-title', i, 9);
			var nameLen = Math.min(9, name.length);
			if((nameLen>0)&&(lastTextDisplayed[i] != name))
			{
				//debug('name='+name+' nameLen='+nameLen);
				var sysexData = new Array(10+nameLen);
				sysexData[0] = 0xF0;
				sysexData[1] = 0x00;
				sysexData[2] = 0x01;
				sysexData[3] = 0x3F;
				sysexData[4] = 0x42;
				sysexData[5] = (i==0)?0x01:0x20;
				sysexData[6] = Math.floor(nameLen/256);// most significant N
				sysexData[7] = nameLen%256;// least significant N
				for(var j=0; j<nameLen; j++) sysexData[8+j] = name.charCodeAt(j);// data
				sysexData[8+nameLen] = 0xF7;
				// send the sysex
				sendMidiSysEx(uniqueId, sysexData, 8+nameLen+1);
				lastTextDisplayed[i] = name;
			}
		}
		// loop in led
		if(loopingInBlinkLed[i]!=-1)
		{
			// actually set the led
			sendMidi(uniqueId,0x90,i,0x34,((loopingInBlinkLed[i]<2) ? 0x7F : 0x00));// Loop In (on or off)
			loopingInBlinkLed[i]++;
			if(loopingInBlinkLed[i]>=4) loopingInBlinkLed[i] = 0;
		}

	
	
	}
}
//----------------------------------------------------------------------------- 
