Hey everyone, I'm new to this - done a few sketches of my own but I just bought an LED strip and when looking at the example sketch for it, and it works, but I can't for the life of me figure out where in this sketch it's sending data to the pins. I'm sure it's in the SendStrip() function but can't figure out exactly what line is sending data. I'm attempting to have it pulse to music and the project has been quite the challenge so far. I've spent a couple days looking at this so if anyone can offer some help I'd be immensely grateful. Thank you!
#include <avr/pgmspace.h>
// ******** DEBUG ==== should auto config to adapt different mother board *********
//#define DATA_1 (PORTF |= 0X01) // DATA 1 // for ATMEGA
//#define DATA_0 (PORTF &= 0XFE) // DATA 0 // for ATMEGA
//#define STRIP_PINOUT DDRF=0xFF // for ATMEGA
#define DATA_1 (PORTC |= 0X01) // DATA 1 // for UNO
#define DATA_0 (PORTC &= 0XFE) // DATA 0 // for UNO
#define STRIP_PINOUT (DDRC=0xFF) // for UNO
PROGMEM const unsigned long pattern_test_rainbow[10][10]={
{0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000},
{0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000},
{0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000},
{0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff},
{0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff},
{0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff},
{0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00},
{0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00},
{0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00},
{0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000},
};
// ***********************************************************************************************************
// *
// * Power Up Init.
// *
// *
// ***********************************************************************************************************
void setup() {
STRIP_PINOUT; // set output pin - DEBUG: should auto detect which mother board for use
reset_strip();
//noInterrupts();
}
// ***********************************************************************************************************
// *
// * Main Loop
// *
// *
// ***********************************************************************************************************
void loop()
{
send_1M_pattern(pattern_test_rainbow, 10, 70);
/*
frame++;
if(frame<=10) LEDSTRIP_PATTERN_0();
if(10<frame<=20) LEDSTRIP_PATTERN_0();
if(20<frame<=30) LEDSTRIP_PATTERN_0();
if(frame>30) frame=1;
*/
//delay(1);
}
/*******************************************************************************
* Function Name : send_1M_pattern
* Description : Transmit pattern to whole 1 meter strip
*
* Input : pointer to ROM pattern; pattern length; frame rate
*
* Output : None
* Return : None
*******************************************************************************/
void send_1M_pattern(const unsigned long data[][10], int pattern_no, int frame_rate)
{
int i=0;
int j=0;
uint32_t temp_data;
for (i=0;i<pattern_no;i++)
{
noInterrupts();
for (j=0;j<10;j++)
{
temp_data=pgm_read_dword_near(&data[i][j]);
send_strip(temp_data);
}
interrupts();
delay(frame_rate);
}
}
/*******************************************************************************
* Function Name : send_strip
* Description : Transmit 24 pulse to LED strip
*
* Input : 24-bit data for the strip
*
* Output : None
* Return : None
*******************************************************************************/
void send_strip(uint32_t data)
{
int i;
unsigned long j=0x800000;
for (i=0;i<24;i++)
{
if (data & j)
{
DATA_1;
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
DATA_0;
}
else
{
DATA_1;
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
DATA_0;
}
j>>=1;
}
}
/*******************************************************************************
* Function Name : reset_strip
* Description : Send reset pulse to reset all color of the strip
*
* Input : None
*
* Output : None
* Return : None
*******************************************************************************/
void reset_strip()
{
DATA_0;
delayMicroseconds(20);
}