Ashok R
Published

RGB Christmas Star

Lights Up & Control the Christmas Star in a smart way with phone

EasyShowcase (no instructions)291
RGB Christmas Star

Things used in this project

Hardware components

NXP LPC810M021FN8
×1
NXP NX1117C
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
RGB LED
×1

Software apps and online services

RGB Star Android App

Hand tools and fabrication machines

LPCXpresso

Story

Read more

Schematics

RGB Star Schematic

Regulator IC may be different one

Code

RGB Star Source

C/C++
#include "lpc8xx_clkconfig.h"
#include "lpc8xx_gpio.h"
#include "lpc8xx_uart.h"

#define RLED_ON()   (LPC_GPIO_PORT->SET0 = 1 << 1)
#define RLED_OFF() 	(LPC_GPIO_PORT->CLR0 = 1 << 1)
#define GLED_ON() 	(LPC_GPIO_PORT->SET0 = 1 << 2)
#define GLED_OFF() 	(LPC_GPIO_PORT->CLR0 = 1 << 2)
#define BLED_ON() 	(LPC_GPIO_PORT->SET0 = 1 << 3)
#define BLED_OFF() 	(LPC_GPIO_PORT->CLR0 = 1 << 3)
#define LPC_UART LPC_UART0

#define TRUE				1
#define true				1
#define FALSE				0
#define false				0

#define ONT_MIN				0
#define ONT_MAX				255
#define PT_MAX				255

#define UART_BAUD_9600	9600

#define SYSTICK_DELAYms		(SystemCoreClock/1000)  	/* Generate 1ms Ticks */
#define SYSTICK_DELAYus		(SystemCoreClock/100000)  	/* Generate .01ms (10us) Ticks */


// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information

volatile uint32_t msTicks=0;
volatile uint8_t RxData[4];
volatile uint8_t RxReady=0;
volatile uint8_t led_EN=0;

extern volatile uint8_t  UARTRxBuffer[BUFSIZE];
extern volatile uint32_t UARTRxCount;
struct Channel{

	volatile uint16_t ONTime;
	volatile uint32_t msPTicks;
	volatile uint8_t Set_Value;
	volatile uint8_t Enabled;
}r,g,b,ch4,ch5;



/* SysTick interrupt happens every 10 ms */
void SysTick_Handler(void)
{
msTicks++;
}

void Data_Init(){


	r.Enabled = false;
	g.Enabled = false;
	b.Enabled = false;


	r.ONTime = 255;
	g.ONTime = 255;
	b.ONTime = 255;


}
/* Main Program */

int main (void) {

uint16_t regVal;

  SystemCoreClockUpdate();

  //SwitchMatrix_Init();

  GPIOInit();

  /* Called for system library in core_cmx.h(x=0 or 3). */
  SysTick_Config( SYSTICK_DELAYus );



  LPC_SWM->PINENABLE0 = 0xffffffbfUL;

  /* Pin Assign 8 bit Configuration */
   /* U0_TXD */
   /* U0_RXD */
   LPC_SWM->PINASSIGN0 = 0xffff0004UL;



  LPC_GPIO_PORT->DIR0 |= (1 << 1);
  LPC_GPIO_PORT->DIR0 |= (1 << 2);
  LPC_GPIO_PORT->DIR0 |= (1 << 3);




	//init_mrt(0x8000);
  Data_Init();

  UARTInit(LPC_USART0,UART_BAUD_9600);

  RLED_ON();
  	  					GLED_ON();
  	  					BLED_ON();

  	  				

	
  while (1)                                /* Loop forever */
  {
    	  if(msTicks >= 255){

	  					msTicks = 0;
	  					RLED_ON();
	  					GLED_ON();
	  					BLED_ON();

	  					r.Enabled = true;
	  					g.Enabled = true;
	  					b.Enabled = true;


	  				 	 }
	  				else if((msTicks >= r.ONTime) && r.Enabled){

	  					RLED_OFF();
	  					r.Enabled = false;

	  					}
	  				else if((msTicks >= g.ONTime) && g.Enabled){

	  					GLED_OFF();
	  					g.Enabled = false;

	  					}
	  				else if((msTicks >= b.ONTime ) && b.Enabled){

	  					BLED_OFF();
	  					b.Enabled = false;

	  					}

	  					if(RxReady == true){


	  				    	RxData[0]=UARTRxBuffer[0];
	  				    	RxData[1]=UARTRxBuffer[1];
	  				    	RxData[2]=UARTRxBuffer[2];
	  				    	RxData[3]=UARTRxBuffer[3];

	  				    	if((RxData[0] <=255) && (RxData[1] <= 255) && (RxData[2] <= 255) && (RxData[0] <= 255) ){

	  				    		r.ONTime = RxData[1];
	  				    		g.ONTime = RxData[2];
	  				    		b.ONTime = RxData[3];
	  				    		led_EN = RxData[0];
	  				    	}


	  				    	RxReady= false;


	  				}
  }
}

Credits

Ashok R

Ashok R

15 projects • 42 followers
Hobbyist/Engineer/Director/Animatior

Comments