Daniel Becerril
Published © GPL3+

Arduino DMX-512 Tester Controller

Control tool for testing and light show by the DMX-512 protocol, ideal for quick tests on fixed or temporary installations of lighting.

IntermediateFull instructions provided19,673
Arduino DMX-512 Tester Controller

Things used in this project

Hardware components

Arduino Mega 2560 & Genuino Mega 2560
Arduino Mega 2560 & Genuino Mega 2560
×1
SparkFun Rotary Potentiometer - 10k Ohm, Linear
×1
Switch Push Button Tactile Single Pole Single Throw Off Momentary
×5
SparkFun Basic 20x4 Character LCD - Black on Green 5V
×1
Transistor 2N2222A TO-18 NPN 75 Volt 0.6 Amp
×2
Key Matrix 4x4
×1
MAX485 Low-Power, Slew-Rate-Limited RS-485/RS-422 Transceivers
×1
Resistor 330 ohm
Resistor 330 ohm
×2
Resistor 1k ohm
Resistor 1k ohm
×2
Resistor 120 ohm
×1
3 mm LED: Green
3 mm LED: Green
×2
Capacitor 1 nF
Capacitor 1 nF
×6
Large terminal with 3 screws
×1
Large terminal with 2 screws
×1
Switch Slide 1 pole, 2 shots, 2 positions
×1
XLR Connector 3 Pin PCB Mount Amphenol AC3FAH2-AU-PRE
×1
XLR Connector 5 Pin PCB Mount Amphenol AC5FAH-AU-B
×1
Male Header 40 Position 1 Row (0.1")
Male Header 40 Position 1 Row (0.1")
×4
Phenolic a face plate of 15 x 20 cm
×1
Base for integrated circuit 8-pin
×1
Photosensitive Dry Film Pcb 30cm*200cm/ 2m
×1

Story

Read more

Custom parts and enclosures

Repository

Cad Cam

Schematics

Repository

PCB

Pcb

Schematic

Esquematico

Code

DMX_Controller.ino

Arduino
// ***************************************************************************************************************************
// ***************************************************************************************************************************
// **																														**
// **										Arduino DMX-512 Tester Controller												**
// **																														**
// **	- Firmware v0.6																										**
// **	- Hardware v0.0 - v0.2																								**
// **																														**
// **	- Compilado en Arduino IDE v1.0.6																					**
// **		http://www.arduino.cc/en/Main/OldSoftwareReleases																**
// **	- Compilado para Arduino Mega 2560 R3																				**
// **		http://www.arduino.cc/en/Main/ArduinoBoardMega2560																**
// **	- Libreria Arduino cuatro universos DMX v0.3 - Deskontrol.net														**
// **		http://www.deskontrol.net/blog/libreria-arduino-cuatro-universos-dmx/)											**
// **	- Libreria LCD v1.2.1 - Francisco Malpartida																		**
// **		https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home													**
// **	- Simulacion en Proteus v7.7 SP2																					**
// **	- Simulacion en Proteus de Arduino - Microcontrolandos																**
// **		http://microcontrolandos.blogspot.mx/2012/12/arduino-componentes-para-o-proteus.html							**
// **																														**
// **	Autor:																												**
// **																														**
// **	Daniel Roberto Becerril Angeles																						**
// **	daniel3514@gmail.com																								**																										**
// **	https://github.com/daniel3514/Arduino-DMX-512-Tester-Controller/													**
// **																														**
// **	Licenciamiento:																										**
// **																														**
// **	GNU General Pubic Licence Version 3																					**
// **		https://www.gnu.org/copyleft/gpl.html																			**
// **																														**
// ***************************************************************************************************************************
// ***************************************************************************************************************************

// Librerias
	#include <LiquidCrystal.h>	// libreria para LCD
	#include <Wire.h>
	#include <EEPROM.h>
	#include <string.h>
	#include <lib_dmx.h>  		// libreria DMX 4 universos deskontrol four universes DMX library  - http://www.deskontrol.net/blog
		
// DMX Library
	#define    DMX512	  (0)   // (250 kbaud - 2 to 512 channels) Standard USITT DMX-512
	//#define  DMX1024    (1)   // (500 kbaud - 2 to 1024 channels) Completely non standard - TESTED ok
	//#define  DMX2048    (2)   // (1000 kbaud - 2 to 2048 channels) called by manufacturers DMX1000K, DMX 4x or DMX 1M ???

// Puertos, variables
	// DMX
		//int DMX_Data_Flux 		= 2;	// control de flujo de datos para dmx, 0 por default 
		int  DMX_Values [515];      	// array de valores actuales DMX
		int  Canal_Actual 		= 1;
	// Botones cursor
		int  Boton_Up     		= 51; 
		int  Boton_Down   		= 45;	
		int  Boton_Left   		= 53;	
		int  Boton_Right  		= 49;	
		int  Boton_Center		= 47;	
		byte LCD_Col_Pos 		= 0;	// posicion en tiempo real de lcd
		byte LCD_Row_Pos 		= 0;	// posicion en tiempo real de lcd
		byte Cursor_Conf[4][20] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},		// config de posiciones de lcd Col Row
								   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
								   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
								   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};		
	// Botones Numerico Array
		int  Boton_Array_1		= 36;
		int  Boton_Array_2		= 34;
		int  Boton_Array_3		= 32;
		int  Boton_Array_4		= 30;
		int  Boton_Array_A		= 44;	
		int  Boton_Array_B		= 42;
		int  Boton_Array_C   	= 40;
		int  Boton_Array_D   	= 38;
		byte Boton_Calc 		= 17;	// valor calculado	# E * F, 17 sin valor calculado
		byte Num_Col_Pos  		= 0;	// posicion en tiempo real de lcd
		byte Num_Row_Pos 		= 0;	// posicion en tiempo real de lcd
		int  Num_Val			= 0;	// valor generado al calculo
		long Boton_Delay_Teclado = 100;	// delay de lectura de boton
	// Potenciometro
		int  Pot				= A15;	// entrada de potenciometro
	// LCD
		int  LCD_RS 			= 8;	// puertos de conexion de LCD
		int  LCD_E  			= 9;
		int  LCD_D4 			= 10;
		int  LCD_D5 			= 11;
		int  LCD_D6 			= 12;
		int  LCD_D7				= 13;
		LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);  //LCD setup
		int  Back_Light_PWM		= 3;	// salida para PWM de Back Light de LCD
		int  Contrast_PWM		= 4;	// salida para pwm de contraste de LCD
		byte Back_Light_On_Off	= 0;	// saber si esta encendida o apagada

void setup() 
	{
		// DMX
			//pinMode(DMX_Data_Flux, 		OUTPUT);
		// Botones cursor
			pinMode(Boton_Up,      		INPUT_PULLUP);
			pinMode(Boton_Down,    		INPUT_PULLUP);
			pinMode(Boton_Left,    		INPUT_PULLUP);
			pinMode(Boton_Right,   		INPUT_PULLUP);
			pinMode(Boton_Center,  		INPUT_PULLUP);
		// Botones numerico
			pinMode(Boton_Array_1, 		OUTPUT);
			pinMode(Boton_Array_2, 		OUTPUT);
			pinMode(Boton_Array_3, 		OUTPUT);
			pinMode(Boton_Array_4,		OUTPUT);
			pinMode(Boton_Array_A, 		INPUT_PULLUP);
			pinMode(Boton_Array_B, 		INPUT_PULLUP);
			pinMode(Boton_Array_C, 		INPUT_PULLUP);
			pinMode(Boton_Array_D, 		INPUT_PULLUP);
			digitalWrite(Boton_Array_1, HIGH);
			digitalWrite(Boton_Array_2, HIGH);
			digitalWrite(Boton_Array_3, HIGH);
			digitalWrite(Boton_Array_4, HIGH);
		// LCD
			pinMode(LCD_RS, 			OUTPUT);
			pinMode(LCD_E,  			OUTPUT);
			pinMode(LCD_D7, 			OUTPUT);
			pinMode(LCD_D6, 			OUTPUT);
			pinMode(LCD_D5, 			OUTPUT);
			pinMode(LCD_D4, 			OUTPUT);
			pinMode(Back_Light_PWM,		OUTPUT);
			lcd.begin(20, 4);							//tamao de LCD				
		// DMX
			ArduinoDmx0.set_tx_address(1);      		// poner aqui la direccion de inicio de DMX 
			ArduinoDmx0.set_tx_channels(512);   		// poner aqui el numero de canales a transmitir 
			ArduinoDmx0.init_tx(DMX512);        		// iniciar transmision universo 0, modo estandar DMX512
		// no conectados
			pinMode(5, OUTPUT);
			digitalWrite(5, LOW);
			pinMode(6, OUTPUT);
			digitalWrite(6, LOW);
			pinMode(7, OUTPUT);
			digitalWrite(7, LOW);
			pinMode(22, OUTPUT);
			digitalWrite(22, LOW);
			pinMode(23, OUTPUT);
			digitalWrite(23, LOW);
			pinMode(24, OUTPUT);
			digitalWrite(24, LOW);
			pinMode(25, OUTPUT);
			digitalWrite(25, LOW);
			pinMode(26, OUTPUT);
			digitalWrite(26, LOW);
			pinMode(27, OUTPUT);
			digitalWrite(27, LOW);
			pinMode(28, OUTPUT);
			digitalWrite(28, LOW);
			pinMode(29, OUTPUT);
			digitalWrite(29, LOW);
			pinMode(31, OUTPUT);
			digitalWrite(31, LOW);
			pinMode(33, OUTPUT);
			digitalWrite(33, LOW);
			pinMode(35, OUTPUT);
			digitalWrite(35, LOW);
			pinMode(37, OUTPUT);
			digitalWrite(37, LOW);
			pinMode(39, OUTPUT);
			digitalWrite(39, LOW);
			pinMode(41, OUTPUT);
			digitalWrite(41, LOW);
			pinMode(43, OUTPUT);
			digitalWrite(43, LOW);
			pinMode(46, OUTPUT);
			digitalWrite(46, LOW);
			pinMode(48, OUTPUT);
			digitalWrite(48, LOW);
			pinMode(50, OUTPUT);
			digitalWrite(50, LOW);
			pinMode(52, OUTPUT);
			digitalWrite(52, LOW);
			pinMode(A0, OUTPUT);
			digitalWrite(A0, LOW);
			pinMode(A1, OUTPUT);
			digitalWrite(A1, LOW);
			pinMode(A2, OUTPUT);
			digitalWrite(A2, LOW);
			pinMode(A3, OUTPUT);
			digitalWrite(A3, LOW);
			pinMode(A4, OUTPUT);
			digitalWrite(A4, LOW);
			pinMode(A5, OUTPUT);
			digitalWrite(A5, LOW);
			pinMode(A6, OUTPUT);
			digitalWrite(A6, LOW);
			pinMode(A7, OUTPUT);
			digitalWrite(A7, LOW);
			pinMode(A8, OUTPUT);
			digitalWrite(A8, LOW);
			pinMode(A9, OUTPUT);
			digitalWrite(A9, LOW);
			pinMode(A10, OUTPUT);
			digitalWrite(A10, LOW);
			pinMode(A11, OUTPUT);
			digitalWrite(A11, LOW);
			pinMode(A12, OUTPUT);
			digitalWrite(A12, LOW);
			pinMode(A13, OUTPUT);
			digitalWrite(A13, LOW);
			pinMode(A14, OUTPUT);
			digitalWrite(A14, LOW);
	}    

void loop()
	{
		digitalWrite(2, HIGH);							// max 485 como salida
		Back_Light_Init();
		Contrast_Init();
		GUI_About();
		GUI_Memory_Init();
	}

void Back_Light_Init()
	{
		// ultimo estado del back light
			byte Back_Light_Value = EEPROM.read(513);
			analogWrite(Back_Light_PWM, Back_Light_Value);
			if (Back_Light_Value == 0)
				{
					Back_Light_On_Off = 0;
				}
			if (Back_Light_Value > 0)
				{
					Back_Light_On_Off = 1;
				}
	}
	
void Contrast_Init()
	{
		// ultimo estado del comtrast
			byte Contrast_Value = EEPROM.read(514);
			analogWrite(Contrast_PWM, Contrast_Value);
	}
	
void Back_Light_En()
	{
		byte Back_Light_Value = EEPROM.read(513);				// lectura del ultimo valor desde la eeprom, 513 es donde se guarda el valor
		// encender
			if (Back_Light_On_Off == 0)							// si esta apagada encenderla
				{
					if (Back_Light_Value == 0)					// la encendemos de todos modos
						{
							analogWrite(Back_Light_PWM, 127);	// aqui el valor a encender en el caso que se haya establecido apagado el back light
						}
					if (Back_Light_Value > 0)
						{
							analogWrite(Back_Light_PWM, Back_Light_Value);	// encender con el valor de la eeprom
						}
					Back_Light_On_Off = 1;
					goto salida;
				}
		// apagar
			if (Back_Light_On_Off == 1)							// si esta encendida apagarla
				{
					analogWrite(Back_Light_PWM, 0);
					Back_Light_On_Off = 0;
				}
		salida:
			{
				delay(300);										// para impedir repeticion del comando
			}
	}
	
void GUI_About()
	{
		byte Firm_Ver_Ent = 0;
		byte Firm_Ver_Dec = 6;
		byte Hard_Ver_Ent = 0;
		byte Hard_Ver_Dec = 0;
		byte ID = 20;
		lcd.clear ();
		lcd.noBlink();									// ocultar cursor
		lcd.setCursor(0, 0);
		for(int numero = 0; numero <= 512; numero ++)	// efecto binario en lcd
			{
				lcd.print (numero, BIN);
			}
		lcd.clear ();
		lcd.setCursor(0, 3);
		lcd.print("http://goo.gl/kdYlj7");
		lcd.setCursor(3, 0);
		lcd.print("Arduino DMX-512");
		lcd.setCursor(1, 1);
		lcd.print("Tester & Controller");
		// Firmware
			lcd.setCursor(0, 2);
			lcd.print("Firm v");
			lcd.print(Firm_Ver_Ent);
			lcd.print(".");
			lcd.print(Firm_Ver_Dec);
		// Hardware
			lcd.setCursor(11, 2);
			lcd.print("Hard v");
			lcd.print(Hard_Ver_Ent);
			lcd.print(".");
			lcd.print(Hard_Ver_Dec);
		delay(2000);  									//retardo de muestra de mensaje
	}

void Multi_Matrix(int inicial)
	{
		// dibujar banco
			Numerico_Write (inicial, 13, 0);
			Numerico_Write (inicial + 14, 17, 0);
		// matrix 1
			Numerico_Write (DMX_Values[inicial], 1, 1);
			Numerico_Write (DMX_Values[inicial + 1], 5, 1);
			Numerico_Write (DMX_Values[inicial + 2], 9, 1);
			Numerico_Write (DMX_Values[inicial + 3], 13, 1);
			Numerico_Write (DMX_Values[inicial + 4], 17, 1);
		// matrix 2
			Numerico_Write (DMX_Values[inicial + 5], 1, 2);
			Numerico_Write (DMX_Values[inicial + 6], 5, 2);
			Numerico_Write (DMX_Values[inicial + 7], 9, 2);
			Numerico_Write (DMX_Values[inicial + 8], 13, 2);
			Numerico_Write (DMX_Values[inicial + 9], 17, 2);
		// matrix 3
			Numerico_Write (DMX_Values[inicial + 10], 1, 3);
			Numerico_Write (DMX_Values[inicial + 11], 5, 3);
			Numerico_Write (DMX_Values[inicial + 12], 9, 3);
			Numerico_Write (DMX_Values[inicial + 13], 13, 3);
			Numerico_Write (DMX_Values[inicial + 14], 17, 3);
	}
	
void GUI_Control_Matrix()
	{
		int Inicial = 1;
		Canal_Actual = 1;
		inicio:
			lcd.clear();
			lcd.setCursor (0, 0);
			lcd.print("c--- Mem Ctr    -");
			Multi_Matrix (Inicial);
			// Cursor
				LCD_Col_Pos = 12;		// posicion de cursor
				LCD_Row_Pos = 0;		// posicion e cursor
			// configuracion de cursor	
				Cursor_Conf_Clear();	// limpiar array
			// Row 0
				Cursor_Conf[0][4]  = 1;	// Memory
				Cursor_Conf[0][8]  = 1;	// Unit
				Cursor_Conf[0][12] = 1;	// Banco Inicial
				Cursor_Conf[0][16] = 1;	// Banco Final
			// Row 1
				Cursor_Conf[1][0]  = 1;
				Cursor_Conf[1][4]  = 1;
				Cursor_Conf[1][8]  = 1;
				Cursor_Conf[1][12] = 1;
				Cursor_Conf[1][16] = 1;
			// Row 2
				Cursor_Conf[2][0]  = 1;
				Cursor_Conf[2][4]  = 1;
				Cursor_Conf[2][8]  = 1;
				Cursor_Conf[2][12] = 1;
				Cursor_Conf[2][16] = 1;
			// Row 3
				Cursor_Conf[3][0]  = 1;
				Cursor_Conf[3][4]  = 1;
				Cursor_Conf[3][8]  = 1;
				Cursor_Conf[3][12] = 1;
				Cursor_Conf[3][16] = 1;
			// navegar
		Banco:
				GUI_Navegar(1, Inicial);
			// Acciones
				// Memory
					if (LCD_Col_Pos == 4 &&  LCD_Row_Pos == 0)
						{
							GUI_Memory();
							goto inicio;
						}
				// Control
					if (LCD_Col_Pos == 8 &&  LCD_Row_Pos == 0)
						{
							GUI_Control_Options();
							goto inicio;
						}
				// Banco Inicial
					if (LCD_Col_Pos == 12 && LCD_Row_Pos == 0)
						{
							Num_Row_Pos = 0;
							Num_Col_Pos = 13;
							Num_Val = Inicial;	// para dejar el numero que estaba si no se cambia
							Numerico_Calc(0);
							if (Num_Val > 498)	// limite de matriz
								{
									Num_Val = 498;
								}
							if (Num_Val == 0)	// limite de matriz
								{
									Num_Val = 1;
								}
							Inicial = Num_Val;
							goto inicio;
						}
				// Banco Final
					if (LCD_Col_Pos == 16 && LCD_Row_Pos == 0)
						{
							Num_Row_Pos = 0;
							Num_Col_Pos = 17;
							if (Inicial == 1)
								Num_Val = 15;
							else	
								Num_Val = Inicial - 14;	// para dejar el numero que estaba si no se cambia
							Numerico_Calc(0);
							if (Num_Val > 512)		// limite de matriz
								{
									Inicial = 498;
									goto inicio;
								}
							if (Num_Val < 15)		// limite de matriz
								{
									Inicial = 1;
									goto inicio;
								}
							Inicial = Num_Val - 14;
							goto inicio;
						}
				// posicion 1
					if (LCD_Col_Pos == 0 && LCD_Row_Pos == 1)
						{
							Canal_Actual = Inicial;
							goto Salida_DMX;
						}
				// posicion 2
					if (LCD_Col_Pos == 4 && LCD_Row_Pos == 1)
						{
							Canal_Actual = Inicial + 1;
							goto Salida_DMX;
						}
				// posicion 3
					if (LCD_Col_Pos == 8 && LCD_Row_Pos == 1)
						{
							Canal_Actual = Inicial + 2;
							goto Salida_DMX;
						}
				// posicion 4
					if (LCD_Col_Pos == 12 && LCD_Row_Pos == 1)
						{
							Canal_Actual = Inicial + 3;
							goto Salida_DMX;
						}
				// posicion 5
					if (LCD_Col_Pos == 16 && LCD_Row_Pos == 1)
						{
							Canal_Actual = Inicial + 4;
							goto Salida_DMX;
						}
				// posicion 6
					if (LCD_Col_Pos == 0 && LCD_Row_Pos == 2)
						{
							Canal_Actual = Inicial + 5;
							goto Salida_DMX;
						}
				// posicion 7
					if (LCD_Col_Pos == 4 && LCD_Row_Pos == 2)
						{
							Canal_Actual = Inicial + 6;
							goto Salida_DMX;
						}
				// posicion 8
					if (LCD_Col_Pos == 8 && LCD_Row_Pos == 2)
						{
							Canal_Actual = Inicial + 7;
							goto Salida_DMX;
						}
				// posicion 9
					if (LCD_Col_Pos == 12 && LCD_Row_Pos == 2)
						{
							Canal_Actual = Inicial + 8;
							goto Salida_DMX;
						}
				// posicion 10
					if (LCD_Col_Pos == 16 && LCD_Row_Pos == 2)
						{
							Canal_Actual = Inicial + 9;
							goto Salida_DMX;
						}
				// posicion 11
					if (LCD_Col_Pos == 0 && LCD_Row_Pos == 3)
						{
							Canal_Actual = Inicial + 10;
							goto Salida_DMX;
						}
				// posicion 12
					if (LCD_Col_Pos == 4 && LCD_Row_Pos == 3)
						{
							Canal_Actual = Inicial + 11;
							goto Salida_DMX;
						}
				// posicion 13
					if (LCD_Col_Pos == 8 && LCD_Row_Pos == 3)
						{
							Canal_Actual = Inicial + 12;
							goto Salida_DMX;
						}
				// posicion 14
					if (LCD_Col_Pos == 12 && LCD_Row_Pos == 3)
						{
							Canal_Actual = Inicial + 13;
							goto Salida_DMX;
						}
				// posicion 15
					if (LCD_Col_Pos == 16 && LCD_Row_Pos == 3)
						{
							Canal_Actual = Inicial + 14;
							goto Salida_DMX;
						}
		Salida_DMX:
			Num_Row_Pos = LCD_Row_Pos;
			Num_Col_Pos = LCD_Col_Pos + 1;
			Num_Val = DMX_Values[Canal_Actual];		// para dejar el numero que estaba si no se cambia
			Numerico_Calc(1);
			if (Num_Val == 612)		// ubicar
				{
					Ubicar();
					Num_Col_Pos = Num_Col_Pos - 4;
				}
			if (Num_Val == 712)		// analogo
				{
					Analog_Read_DMX(Num_Col_Pos - 2, Num_Row_Pos);
					Num_Col_Pos = Num_Col_Pos - 4;
					goto Banco;
				}
			if (Num_Val > 255)
				{
					Num_Val = 255;
					Numerico_Write (255, Num_Col_Pos + 2, Num_Row_Pos);
				}
			ArduinoDmx0.TxBuffer[Canal_Actual - 1] = Num_Val;
			DMX_Values[Canal_Actual] = Num_Val;
			goto Banco;		
	}
	
void Cursor_Conf_Clear()
	{
		for (byte Conteo_Col = 0; Conteo_Col <= 19; Conteo_Col ++)
			{
				for (byte Conteo_Row = 0; Conteo_Row <= 3; Conteo_Row ++)
					{
						Cursor_Conf[Conteo_Row][Conteo_Col] = 0;
					}
			}
	}
	
void GUI_Navegar(byte matrix, int banco)
	{
		long Boton_Delay_Cursor  = 300;			// delay de lectura de boton
		byte LCD_Col_Pos_Ant;					// saber el estado anterior para borrar cursor
		byte LCD_Row_Pos_Ant;					// saber el estado anterior para borrar cursor
		// guardar valor anterior de row col
			LCD_Col_Pos_Ant = LCD_Col_Pos;
			LCD_Row_Pos_Ant = LCD_Row_Pos;
		// Dibujar cursor
			lcd.setCursor (LCD_Col_Pos, LCD_Row_Pos);
			lcd.print(">"); 													
		// navegacion
			Dibujar:
				byte Dibujar_Cursor = 0;		// saber si dibujar cursor para evitar repeticiones en lcd, 0 no dibujar, 1 dibujar >, 2 dibujar +
				// LCD Back Light *
					digitalWrite(Boton_Array_1, LOW);	// lectura linea 1
						if (digitalRead(Boton_Array_D) == LOW)
							{
								delay(Boton_Delay_Teclado);
								Back_Light_En();
							}
					digitalWrite(Boton_Array_1, HIGH);	// lectura linea 1
				// Left
					if (digitalRead(Boton_Left) == LOW)
						{
							delay (Boton_Delay_Cursor);
							byte Salida_Left = 0;
							byte LCD_Col_Pos_Temp = 0;
							LCD_Col_Pos_Temp = LCD_Col_Pos;
							while (Salida_Left == 0)
								{
									if (LCD_Col_Pos_Temp == 0)
										{
											LCD_Col_Pos_Temp = 20;
										}
											LCD_Col_Pos_Temp = LCD_Col_Pos_Temp - 1;
									if (Cursor_Conf[LCD_Row_Pos][LCD_Col_Pos_Temp] == 1)
										{
											LCD_Col_Pos = LCD_Col_Pos_Temp;
											Dibujar_Cursor = 1;
											Salida_Left = 1;
										}
								}
							goto Salida;
						}
				// Right
					if (digitalRead(Boton_Right) == LOW)
						{
							delay(Boton_Delay_Cursor);
							byte Salida_Right = 0;
							byte LCD_Col_Pos_Temp = 0;
							LCD_Col_Pos_Temp = LCD_Col_Pos;
							while (Salida_Right == 0)
								{
									LCD_Col_Pos_Temp = LCD_Col_Pos_Temp + 1;
									if (LCD_Col_Pos_Temp >= 20)
										{
											LCD_Col_Pos_Temp = 0;	// regresar al cero
										}
									if (Cursor_Conf[LCD_Row_Pos][LCD_Col_Pos_Temp] == 1)
										{
											LCD_Col_Pos = LCD_Col_Pos_Temp;
											Dibujar_Cursor = 1;
											Salida_Right = 1;
										}
								}
							goto Salida;
						}
				// Down
					if (digitalRead(Boton_Down) == LOW)
						{
							delay(Boton_Delay_Cursor);
							byte Salida_Down = 0;
							byte LCD_Row_Pos_Temp = 0;
							LCD_Row_Pos_Temp = LCD_Row_Pos;
							while (Salida_Down == 0)
								{
									LCD_Row_Pos_Temp = LCD_Row_Pos_Temp + 1;
									if (LCD_Row_Pos_Temp >= 4)
										{
											LCD_Row_Pos_Temp = 0;	// regresar al cero
										}
									if (Cursor_Conf[LCD_Row_Pos_Temp][LCD_Col_Pos] == 1)
										{
											LCD_Row_Pos = LCD_Row_Pos_Temp;
											Dibujar_Cursor = 1;
											Salida_Down = 1;
										}
								}
							goto Salida;
						}
				// Up
					if (digitalRead(Boton_Up) == LOW)
						{
							delay(Boton_Delay_Cursor);
							byte Salida_Up = 0;
							byte LCD_Row_Pos_Temp;
							LCD_Row_Pos_Temp = LCD_Row_Pos;
							while (Salida_Up == 0)
								{
									if (LCD_Row_Pos_Temp <= 0)
										{
											LCD_Row_Pos_Temp = 4;
										}
									LCD_Row_Pos_Temp = LCD_Row_Pos_Temp - 1;
									if (Cursor_Conf[LCD_Row_Pos_Temp][LCD_Col_Pos] == 1)
										{
											Dibujar_Cursor = 1;
											LCD_Row_Pos = LCD_Row_Pos_Temp;
											Salida_Up = 1;
										}
								}
							goto Salida;
						}
				// Center
					if (digitalRead(Boton_Center) == LOW)
						{
							delay(Boton_Delay_Cursor);
							byte Salida_Center = 0;
							while (Salida_Center == 0)
								{
									if (Cursor_Conf[LCD_Row_Pos][LCD_Col_Pos] == 1)
										{
											Dibujar_Cursor = 2;	// dibujar +
											Salida_Center = 1;
										}
								}
						}
			Salida:
				// Dibujar Cursor
					if (Dibujar_Cursor > 0)
						{
							if (Dibujar_Cursor == 1)
								{
									// borra el anterior
										lcd.setCursor (LCD_Col_Pos_Ant, LCD_Row_Pos_Ant);
										lcd.print(" "); 
									// escribir >
										lcd.setCursor (LCD_Col_Pos, LCD_Row_Pos);
										lcd.print(">");
									// matrix print posicion
										if (matrix == 1)
											{
												// banco inicial
													if (LCD_Col_Pos == 12 && LCD_Row_Pos == 0)
														{
															lcd.setCursor(1, 0);
															lcd.print("---");
															goto salida;
														}
												// banco  final
													if (LCD_Col_Pos == 16 && LCD_Row_Pos == 0)
														{
															lcd.setCursor(1, 0);
															lcd.print("---");
															goto salir;
														}
												// Memory
													if (LCD_Col_Pos == 4 && LCD_Row_Pos == 0)
														{
															lcd.setCursor(1, 0);
															lcd.print("---");
															goto salida;
														}
												// Unitary
													if (LCD_Col_Pos == 8 && LCD_Row_Pos == 0)
														{
															lcd.setCursor(1, 0);
															lcd.print("---");
															goto salida;
														}
												// banco 1
													if (LCD_Col_Pos == 0 && LCD_Row_Pos == 1)
														{
															Numerico_Write (banco, 1, 0);
															goto salida;
														}
												// banco 2
													if (LCD_Col_Pos == 4 && LCD_Row_Pos == 1)
														{
															Numerico_Write (banco + 1, 1, 0);
															goto salida;
														}
												// banco 3
													if (LCD_Col_Pos == 8 && LCD_Row_Pos == 1)
														{
															Numerico_Write (banco + 2, 1, 0);
															goto salida;
														}
												// banco 4
													if (LCD_Col_Pos == 12 && LCD_Row_Pos == 1)
														{
															Numerico_Write (banco + 3, 1, 0);
															goto salida;
														}
												// banco 5
													if (LCD_Col_Pos == 16 && LCD_Row_Pos == 1)
														{
															Numerico_Write (banco + 4, 1, 0);
															goto salida;
														}
												// banco 6
													if (LCD_Col_Pos == 0 && LCD_Row_Pos == 2)
														{
															Numerico_Write (banco + 5, 1, 0);
															goto salida;
														}
												// banco 7
													if (LCD_Col_Pos == 4 && LCD_Row_Pos == 2)
														{
															Numerico_Write (banco + 6, 1, 0);
															goto salida;
														}
												// banco 8
													if (LCD_Col_Pos == 8 && LCD_Row_Pos == 2)
														{
															Numerico_Write (banco + 7, 1, 0);
															goto salida;
														}
												// banco 9
													if (LCD_Col_Pos == 12 && LCD_Row_Pos == 2)
														{
															Numerico_Write (banco + 8, 1, 0);
															goto salida;
														}
												// banco 10
													if (LCD_Col_Pos == 16 && LCD_Row_Pos == 2)
														{
															Numerico_Write (banco + 9, 1, 0);
															goto salida;
														}
												// banco 11
													if (LCD_Col_Pos == 0 && LCD_Row_Pos == 3)
														{
															Numerico_Write (banco + 10, 1, 0);
															goto salida;
														}
												// banco 12
													if (LCD_Col_Pos == 4 && LCD_Row_Pos == 3)
														{
															Numerico_Write (banco + 11, 1, 0);
															goto salida;
														}
												// banco 13
													if (LCD_Col_Pos == 8 && LCD_Row_Pos == 3)
														{
															Numerico_Write (banco + 12, 1, 0);
															goto salida;
														}
												// banco 14
													if (LCD_Col_Pos == 12 && LCD_Row_Pos == 3)
														{
															Numerico_Write (banco + 13, 1, 0);
															goto salida;
														}
												// banco 15
													if (LCD_Col_Pos == 16 && LCD_Row_Pos == 3)
														{
															Numerico_Write (banco + 14, 1, 0);
															goto salida;
														}
												// escribir guion de bancos
												salida:
													lcd.setCursor(16, 0);
													lcd.print("-");
												salir:
													{}
											}
								}
							else
								{
									// escribir +
										lcd.setCursor (LCD_Col_Pos, LCD_Row_Pos);
										lcd.print("+");
								}
			
							//salida
								LCD_Col_Pos_Ant = LCD_Col_Pos;
								LCD_Row_Pos_Ant = LCD_Row_Pos;
								if (Dibujar_Cursor == 2)
									{
										goto Salir;
									}
								else	
									{
										Dibujar_Cursor = 0;
									}
						}
			goto Dibujar;
			Salir: {}
	}

void GUI_Memory_Init()
	{
		lcd.clear ();
		// Texto
			lcd.setCursor (0, 0);
			lcd.print("Initial Memory:");
			lcd.setCursor (2, 2);
			lcd.print("Empty");
			lcd.setCursor (9, 2);
			lcd.print("Load");
			lcd.setCursor (15, 2);
			lcd.print("Clear");
		// Cursor
			LCD_Col_Pos = 1;			// posicion de cursor
			LCD_Row_Pos = 2;
		// configuracion de cursor	
			Cursor_Conf_Clear();		// limpiar array
			// Acciones
				Cursor_Conf[2][1]  = 1;	// Empty
				Cursor_Conf[2][8]  = 1; // Load
				Cursor_Conf[2][14] = 1;	// Clear
		// navegar
			GUI_Navegar(0, 0);
		// Acciones
			// Load
				if (LCD_Col_Pos == 8 && LCD_Row_Pos == 2)
					{
						EEPROM_Load();
						GUI_Control_Options();
					}
			// Clear
				if (LCD_Col_Pos == 14 && LCD_Row_Pos == 2)
					{
						EEPROM_Clear();
						GUI_Control_Options();
					}
			// Empty
				if (LCD_Col_Pos == 1 && LCD_Row_Pos == 2)
					{
						GUI_Control_Options();
					}
	}
	
void GUI_Memory()
	{
		lcd.clear ();
		// Texto
			lcd.setCursor (0, 0);
			lcd.print("Memory Options:");
			lcd.setCursor (1, 2);
			lcd.print("Save");
			lcd.setCursor (1, 3);
			lcd.print("Load");
			lcd.setCursor (7, 2);
			lcd.print("Empty");
			lcd.setCursor (7, 3);
			lcd.print("Clear");
			lcd.setCursor (14, 3);
			lcd.print("Cancel");
		// Cursor
			LCD_Col_Pos = 0;			// posicion de cursor
			LCD_Row_Pos = 2;
		// configuracion de cursor	
			Cursor_Conf_Clear();		// limpiar array
			// Acciones
				Cursor_Conf[2][0]  = 1;	// Save
				Cursor_Conf[3][0]  = 1; // Load
				Cursor_Conf[3][6]  = 1;	// Clear
				Cursor_Conf[2][6]  = 1;	// Empty
				Cursor_Conf[3][13] = 1;	// Cancel
		// navegar
			GUI_Navegar(0, 0);
		// Acciones
			// Load
				if (LCD_Col_Pos == 0 && LCD_Row_Pos == 3)
					{
						EEPROM_Load();
					}
			// Clear
				if (LCD_Col_Pos == 6 && LCD_Row_Pos == 3)
					{
						EEPROM_Clear();
					}
			// Save
				if (LCD_Col_Pos == 0 && LCD_Row_Pos == 2)
					{
						EEPROM_Save();
					}
			// Empty
				if (LCD_Col_Pos == 6 && LCD_Row_Pos == 2)
					{
						EEPROM_Empty();
					}
			// Cancel
				if (LCD_Col_Pos == 3 && LCD_Row_Pos == 13)
					{

					}
	}

void EEPROM_Save()
	{
		lcd.clear ();
		lcd.setCursor (17, 1);
		for(int Canal = 1; Canal <= 512; Canal ++)
			{
				EEPROM.write(Canal, DMX_Values[Canal]);          		// lectura desde EEPROM
				lcd.print (Canal, BIN);
			}
		lcd.clear ();
		lcd.setCursor (3, 1);
		lcd.print ("Memory Saved!");
		delay (1000);
	}
	
void EEPROM_Load()
	{
		lcd.clear ();
		lcd.setCursor (17, 1);
		for(int Canal = 1; Canal <= 512; Canal ++)
			{
				DMX_Values[Canal] = EEPROM.read(Canal);          		// lectura desde EEPROM
				ArduinoDmx0.TxBuffer[Canal - 1] = DMX_Values[Canal]; 	// salida a DMX
				lcd.print (Canal, BIN);
			}
		lcd.clear ();
		lcd.setCursor (3, 1);
		lcd.print ("Memory Loaded!");
		delay (1000);
	}
	
void EEPROM_Empty()
	{
		lcd.clear ();
		lcd.setCursor (17, 1);
		for(int Canal = 0; Canal <= 512; Canal ++)
			{
				DMX_Values[Canal] = 0;          		// lectura desde EEPROM
				ArduinoDmx0.TxBuffer[Canal] = 0; 		// salida a DMX
				lcd.print (Canal, BIN);
			}
		lcd.clear ();
		lcd.setCursor (3, 1);
		lcd.print ("Memory Emptied!");
		delay (1000);
	}
	
void EEPROM_Clear()
	{
		lcd.clear ();
		lcd.setCursor (17, 1);
		for(int Canal = 0; Canal <= 512; Canal ++)
			{
				DMX_Values[Canal] = 0;          		// lectura desde EEPROM
				ArduinoDmx0.TxBuffer[Canal] = 0; 		// salida a DMX
				EEPROM.write (Canal, 0);				// escritura EEPROM
				lcd.print (Canal, BIN);
			}
		lcd.clear ();
		lcd.setCursor (3, 1);
		lcd.print ("Memory Cleaned!");
		delay (1000);
...

This file has been truncated, please download it to see its full contents.

Repository

Credits

Daniel Becerril

Daniel Becerril

1 project • 7 followers

Comments