CART
  • Cart is empty.

    ItemQuantityPrice

    Total: $0

Led [Arduino ATmega2560]


Code

 

Project includes single file led.ino which contains 3 functions: setup(), loop() and ProcessLeds().

 

Function setup() is called once when a firmware starts. It configures serial port UART1 as 115200, 8N1. Also it prints greeting message to serial port.

 

Function loop() contains software logic. The logic is very simple: call ProcessLeds() function for each switch/leds group on 8051 I/O Module  (red, orange, yellow, green) and wait 5 seconds before next iteration.

 

Function ProcessLeds() executes code for each switch/leds group:

  • prints name of group to serial port
  • loop through all pins in group
  • if pin marked as unused prints message taht pin is not connected
  • if pin is configured it set pin mode as INPUT and read its state
  • if pin state is HIGH it means that switch in OFF position
  • if pin state is LOW it means that switch in ON position
  • configure pin as OUTPUT and set it to HIGH. This code turns led on
 

Each switch/leds group configured using special structure defined in led.h file. each group have its name and also set of pins. Some pins can be marked as UNUSED_PIN. This means that pin cannot be controlled from software. All groups configured as global variables in the beginning of led.ino file.

 

Please see MINI-MAX Microcontroller Board Family Interchangeable Port Mapping for more information.

 

When software is running you should see state of switches in console. Also some leds on 8051 I/O Module should be on.

Toolkit:AVR Development System

Location:\bipom\devtools\Arduino\ATmega2560\Examples\Led\

Photos


MINI-MAX/AVR-C Board connected to MicroTRAK Carrier Board MINI-MAX/AVR-C Board connected to MicroTRAK Carrier Board
8051 I/O Module and MINI-MAX/AVR-C Board connected to MicroTRAK Carrier Board 8051 I/O Module and MINI-MAX/AVR-C Board connected to MicroTRAK Carrier Board
8051 I/O Module when LED example is running 8051 I/O Module when LED example is running
Terminal window in Micro-IDE when LED example is running Terminal window in Micro-IDE when LED example is running

Code Example


#include "led.h"

const IO_GROUP X3_RED = 
{
	"X3 LCD CONNECTOR, RED",
	{
		{45,"CTRL","HL1","S1-1"},
		{44,"READ","HL3","S1-2"},
		{43,"STROBE","HL5","S1-3"},
		{UNUSED_PIN,"N/C","HL7","S1-4"},
		{49,"LD0","HL9","S1-5"},
		{48,"LD1","HL11","S1-6"},
		{47,"LD2","HL13","S1-7"},
		{46,"LD3","HL15","S1-8"}
	}
};

const IO_GROUP X6_ORANGE = 
{
	"X6 EXPANSION CONNECTOR, ORANGE",
	{
		{11,"IO1","HL17","S2-1"},
		{10,"IO0","HL19","S2-2"},
		{13,"IO3","HL21","S2-3"},
		{12,"IO2","HL23","S2-4"},
		{38,"IO5","HL25","S2-5"},
		{UNUSED_PIN,"IO4","HL27","S2-6"},
		{21,"I2C_SCL","HL29","S2-7"},
		{20,"I2C_SDA","HL31","S2-8"}
	}
};

const IO_GROUP X4_YELLOW= 
{
	"X4 KEYPAD CONNECTOR, YELLOW",
	{
		{62,"KEY0","HL2","S3-1"},
		{63,"KEY0","HL4","S3-2"},
		{64,"KEY0","HL6","S3-3"},
		{65,"KEY0","HL8","S3-4"},
		{7,"KEY0","HL10","S3-5"},
		{8,"KEY0","HL12","S3-6"},
		{9,"KEY0","HL14","S3-7"},
		{UNUSED_PIN,"KEY0","HL16","S3-8"}
	}
};

const IO_GROUP X6_GREEN = 
{
	"X6 EXPANSION CONNECTOR, GREEN",
	{
		{17,"PL4","HL18","S4-1"},
		{16,"PL4","HL20","S4-2"},
		{UNUSED_PIN,"PL4","HL22","S4-3"},
		{50,"PL4","HL24","S4-4"},
		{52,"PL4","HL26","S4-5"},
		{53,"PL4","HL28","S4-6"},
		{30,"PL4","HL30","S4-7"},
		{51,"PL4","HL32","S4-8"}		
	}
};


void setup() 
{ 
  	Serial1.begin(115200); 

  	// prints string with ending line break 

	Serial1.println("BiPOM Arduino"); 
	Serial1.println("LED Example"); 
} 


void loop() 
{ 
	// RED LED group of input pins, X3 LCD connector

	ProcessLeds((void*)&X3_RED);
	
	// ORANGE LED group of input pins, X7 EXPANSION connector

	ProcessLeds((void*)&X6_ORANGE);

	// YELLOW LED group of input pins, X4 KEYPAD connector

	ProcessLeds((void*)&X4_YELLOW);

	// GREEN	LED group of output pins, X7 EXPANSION connector

	ProcessLeds((void*)&X6_GREEN);

	delay(5000);		
} 


void ProcessLeds(void *pGroup) 
{

	int ndx;
	IO_GROUP	*pGrp = (IO_GROUP *)pGroup;

	Serial1.println("");
	Serial1.println("");
	Serial1.print("( ");
	Serial1.print(pGrp->name);
	Serial1.println(" LED group )");

	for(ndx=0; ndx<MAX_PIN_PER_GROUP; ndx++)
	{
		Serial1.print("Switch  ");
		Serial1.print(pGrp->pin[ndx].nameSwitch);
		
		if (pGrp->pin[ndx].numPin == UNUSED_PIN) 		  
		{
			Serial1.println("  is not connected");
			continue;
		}
			
		pinMode(pGrp->pin[ndx].numPin, INPUT);		
		int state = digitalRead(pGrp->pin[ndx].numPin);
		
		pinMode(pGrp->pin[ndx].numPin, OUTPUT);	
		digitalWrite(pGrp->pin[ndx].numPin, HIGH);
		
		if(state == HIGH)
		{
			Serial1.println(" is OFF"); 
		}
		else
		{
			Serial1.println(" is ON"); 
		}
	}
}