Go Down

Topic: only one LED is lighting (Read 1 time) previous topic - next topic

moyzie

Dec 26, 2012, 02:47 am Last Edit: Dec 26, 2012, 02:50 am by moyzie Reason: 1
okay some hardware info first:
1 x Arduino Mega 2560
12 x RGB led WS801
power (red wire) 5v
- (grey and blue wire) in gnd
clk (green wire) in pin 52
Data (white wire) in pin 51

Code: [Select]
/
//LEDType = WS2801
//HardwareSPI = True
//LCDDisplay = False
//DualStrip =False
//StripControl1 = 1
//StripControl2 = 1
//bitmapWidth = 44
//WandLEDs = 12
//delayOffset = 0
//numOffset = 0
//sdiPin1 = 51
//sdiPin2 = 51
//clkPin1 = 52
//clkPin2 = 1
//StartDelay = 1000
//EndDelay = 1000
//StrobeOn = 629
//StrobeOff = 0
// Lightwand code generated by Phil Wright
#include <avr/pgmspace.h>
#include <SPI.h>
#define GET_FAR_ADDRESS(var) \
({ \
uint_farptr_t tmp; \
__asm__ __volatile__( \
"ldi    %A0, lo8(%1)"  "\n\t"    \
"ldi    %B0, hi8(%1)"  "\n\t"    \
"ldi    %C0, hh8(%1)"  "\n\t"    \
"clr    %D0"  "\n\t"    \
: \
"=d" (tmp) \
: \
"p"  (&(var)) \
);   \
tmp; \
})
#define STRIP_LENGTH 12 // Total LEDs on this wand
#define STRIP_WIDTH 44 // Width on this strip
#if defined(ARDUINO) && ARDUINO >= 100
#else
const uint8_t SS = 50;  // Move the SS pin out of the way of the LCD Display (if installed)
#endif
int StripControl1 = 1; //Control Wire for Dual Strip no. 1
long buffer[STRIP_LENGTH];
int tmpbuffer[4];
long lCntr[1];
boolean firstloop=true;
static const uint8_t bitmap_0 [] PROGMEM=
void writeRGB(uint8_t r,uint8_t g,uint8_t b,int nStrip)
{
 SPI.transfer(r);
 SPI.transfer(g);
 SPI.transfer(b);
 digitalWrite(StripControl1, LOW);
}
void blank_strip()
{
for(int x = 0 ; x < STRIP_LENGTH; x++)
 buffer[x] = 0;
}
void post_frame (void) {
for(int LED_number = 0 ; LED_number < STRIP_LENGTH ; LED_number++) {
long this_led_color = buffer[LED_number]; //24 bits of color data
writeRGB((this_led_color >> 16) & 0xff,(this_led_color >> 8) & 0xff,(this_led_color) & 0xff,StripControl1);
}
delayMicroseconds(800);
}
void setup() {
pinMode(SS, OUTPUT);
SPI.begin();
blank_strip();
delay(1000);
}
void loop() {
for(int x=0;x<STRIP_WIDTH;x++) {
uint_farptr_t farptr;
if(x % 100 ==0) {
switch(x / 100) {
case 0:
farptr=GET_FAR_ADDRESS(bitmap_0);
break;
}
}
int bufpos=0;
while(bufpos<STRIP_LENGTH) {
int repeatcolor=pgm_read_byte_far(farptr++);
tmpbuffer[1]=pgm_read_byte_far(farptr++);
tmpbuffer[2]=pgm_read_byte_far(farptr++);
tmpbuffer[3]=pgm_read_byte_far(farptr++);
for(int j=0;j<repeatcolor;j++) {
buffer[bufpos]=(long)tmpbuffer[1] << 16;
buffer[bufpos]|=(long)tmpbuffer[2] << 8;
buffer[bufpos++]|=(long)tmpbuffer[3];
}
}
post_frame();
delay(629);
}
blank_strip();post_frame();
delay(1000);
}


With this code all I am getting is the first LED lighting in a green colour. it should be all 12 fading green to blue over 30 secs I can't find why there is only one led lighting the others are all just white with no change.
I have a program from wrightonline downloaded that created that code from here http://www.wright-online.com/Drupal/?q=node/3

there was a bunch or 0's and 1's in the middle i had to wipe because the post went past the 9500 characters max length
regards
moyzie

moyzie

this was the code i removed
Code: [Select]
boolean firstloop=true;
static const uint8_t bitmap_0 [] PROGMEM={0x02,0x2B,0xAC,0x06,0x01,0x35,0xD0,0x06,0x01,0x3B,0xF2,0x06,0x03,0x36,0xEC,0x06,0x04,0x38,0xEE,0x06,0x01,0x36,0xEE,0x06,
0x02,0x26,0xBE,0x04,0x01,0x37,0xEB,0x06,0x01,0x3B,0xF4,0x06,0x03,0x36,0xF0,0x06,0x04,0x39,0xF3,0x06,0x01,0x36,0xF3,0x06,
0x02,0x1F,0xAD,0x04,0x01,0x28,0xE0,0x06,0x01,0x2C,0xF2,0x06,0x03,0x2A,0xEC,0x09,0x02,0x2A,0xEE,0x09,0x01,0x2A,0xEF,0x09,0x02,0x2A,0xEE,0x09,
0x02,0x19,0xAD,0x04,0x01,0x22,0xE0,0x06,0x01,0x24,0xF2,0x09,0x03,0x25,0xEF,0x09,0x01,0x25,0xEE,0x09,0x02,0x25,0xEF,0x09,0x01,0x24,0xEE,0x09,0x01,0x25,0xEE,0x09,
0x02,0x13,0xAD,0x04,0x01,0x1A,0xE0,0x06,0x01,0x1E,0xF2,0x06,0x01,0x1F,0xEF,0x06,0x01,0x1C,0xEC,0x06,0x01,0x1D,0xEC,0x06,0x01,0x1C,0xEE,0x06,0x01,0x1C,0xEF,0x06,0x01,0x1D,0xEF,0x06,0x01,0x1C,0xEF,0x06,0x01,0x1C,0xEE,0x06,
0x02,0x0E,0xAD,0x04,0x01,0x17,0xE0,0x07,0x01,0x19,0xF2,0x06,0x01,0x17,0xEF,0x07,0x02,0x17,0xEF,0x06,0x01,0x17,0xEE,0x06,0x01,0x16,0xEE,0x06,0x03,0x17,0xEE,0x06,
0x02,0x0C,0xAD,0x02,0x01,0x10,0xE0,0x06,0x01,0x13,0xF2,0x06,0x01,0x10,0xEC,0x06,0x02,0x13,0xEF,0x06,0x05,0x13,0xEE,0x06,
0x02,0x06,0xAF,0x04,0x01,0x0A,0xE0,0x07,0x01,0x0C,0xF2,0x06,0x03,0x0C,0xEC,0x06,0x04,0x0C,0xEF,0x06,0x01,0x0C,0xEE,0x06,
0x02,0x04,0xAD,0x04,0x01,0x06,0xE0,0x06,0x01,0x09,0xF2,0x06,0x03,0x06,0xEF,0x06,0x05,0x09,0xEE,0x06,
0x02,0x04,0xAB,0x06,0x01,0x07,0xE1,0x09,0x01,0x07,0xF2,0x09,0x03,0x07,0xED,0x09,0x04,0x07,0xEC,0x08,0x01,0x07,0xEC,0x09,
0x02,0x04,0xA7,0x08,0x01,0x07,0xDE,0x0C,0x01,0x07,0xF0,0x0C,0x02,0x07,0xE6,0x0D,0x01,0x07,0xE9,0x0C,0x04,0x06,0xE8,0x0C,0x01,0x07,0xE8,0x0C,
0x02,0x04,0xA4,0x0C,0x01,0x07,0xDF,0x10,0x01,0x07,0xEF,0x10,0x01,0x07,0xE3,0x11,0x01,0x07,0xE2,0x11,0x01,0x07,0xE2,0x10,0x04,0x07,0xE5,0x10,0x01,0x07,0xE2,0x10,
0x02,0x04,0x9E,0x0E,0x01,0x07,0xDA,0x15,0x01,0x07,0xEB,0x16,0x01,0x07,0xDD,0x14,0x02,0x07,0xDF,0x15,0x01,0x07,0xDE,0x14,0x01,0x07,0xDF,0x14,0x01,0x07,0xDE,0x14,0x01,0x07,0xDF,0x14,0x01,0x07,0xDE,0x14,
0x02,0x02,0x9A,0x11,0x01,0x07,0xD4,0x18,0x01,0x06,0xE5,0x1A,0x01,0x06,0xD6,0x1B,0x01,0x06,0xD9,0x18,0x01,0x06,0xD8,0x18,0x02,0x06,0xD8,0x1B,0x01,0x07,0xD8,0x1B,0x01,0x07,0xD8,0x1A,0x01,0x06,0xD8,0x18,
0x02,0x02,0x96,0x19,0x01,0x04,0xD1,0x1E,0x01,0x06,0xDE,0x20,0x01,0x06,0xD0,0x1E,0x02,0x07,0xD3,0x1E,0x01,0x06,0xD2,0x1E,0x01,0x06,0xD5,0x1E,0x01,0x07,0xD5,0x1E,0x01,0x06,0xD2,0x20,0x01,0x07,0xD2,0x1E,
0x02,0x02,0x93,0x1D,0x01,0x04,0xCB,0x27,0x01,0x07,0xD9,0x29,0x01,0x04,0xCA,0x24,0x02,0x04,0xCD,0x27,0x03,0x07,0xCC,0x27,0x01,0x07,0xCF,0x27,0x01,0x04,0xCC,0x27,
0x02,0x02,0x8F,0x1E,0x01,0x04,0xC2,0x2D,0x01,0x07,0xD1,0x2F,0x01,0x04,0xC5,0x2A,0x02,0x04,0xC4,0x2A,0x04,0x07,0xC7,0x2D,0x01,0x04,0xC6,0x2D,
0x02,0x02,0x89,0x24,0x01,0x04,0xBA,0x30,0x01,0x07,0xC8,0x34,0x01,0x04,0xBC,0x30,0x01,0x04,0xBF,0x30,0x01,0x04,0xBF,0x33,0x01,0x04,0xBE,0x32,0x01,0x07,0xC1,0x33,0x01,0x07,0xBE,0x33,0x01,0x07,0xBF,0x33,0x01,0x07,0xBE,0x32,
0x02,0x04,0x82,0x2A,0x01,0x04,0xB4,0x3B,0x01,0x04,0xC0,0x3C,0x01,0x04,0xB7,0x38,0x01,0x04,0xB6,0x39,0x01,0x04,0xB6,0x38,0x01,0x07,0xB9,0x3B,0x01,0x07,0xB6,0x38,0x01,0x07,0xB6,0x3B,0x01,0x07,0xB6,0x38,0x01,0x04,0xB6,0x3B,
0x02,0x02,0x7E,0x2F,0x01,0x04,0xAC,0x40,0x01,0x04,0xB9,0x44,0x01,0x04,0xAF,0x40,0x02,0x04,0xAE,0x40,0x02,0x07,0xAE,0x43,0x01,0x04,0xAE,0x43,0x01,0x04,0xB1,0x40,0x01,0x04,0xAE,0x40,
0x02,0x02,0x79,0x35,0x01,0x04,0xA4,0x46,0x01,0x04,0xB0,0x4D,0x01,0x04,0xA7,0x46,0x01,0x04,0xA6,0x48,0x01,0x04,0xA7,0x48,0x01,0x04,0xA6,0x4B,0x01,0x04,0xA9,0x48,0x01,0x04,0xA9,0x49,0x02,0x04,0xA6,0x48,
0x02,0x02,0x71,0x3D,0x01,0x04,0x9D,0x51,0x01,0x04,0xA9,0x55,0x01,0x05,0x9F,0x4F,0x02,0x05,0x9E,0x51,0x01,0x04,0x9E,0x50,0x01,0x04,0x9E,0x51,0x01,0x04,0xA1,0x51,0x01,0x05,0x9E,0x50,0x01,0x05,0x9E,0x51,
0x02,0x02,0x6B,0x40,0x01,0x04,0x95,0x59,0x01,0x04,0x9E,0x5C,0x01,0x05,0x97,0x59,0x01,0x05,0x96,0x59,0x01,0x05,0x96,0x56,0x03,0x04,0x99,0x59,0x01,0x04,0x96,0x59,0x01,0x05,0x99,0x59,
0x02,0x02,0x64,0x44,0x01,0x04,0x8A,0x5F,0x01,0x04,0x97,0x64,0x01,0x05,0x8F,0x60,0x01,0x05,0x8F,0x61,0x01,0x05,0x8F,0x5E,0x03,0x04,0x8E,0x61,0x01,0x05,0x8F,0x61,0x01,0x05,0x8E,0x61,
0x02,0x02,0x5E,0x4D,0x01,0x05,0x82,0x66,0x01,0x05,0x8C,0x6F,0x01,0x05,0x84,0x68,0x02,0x05,0x84,0x69,0x02,0x05,0x87,0x68,0x01,0x05,0x87,0x69,0x02,0x05,0x87,0x68,
0x02,0x00,0x5A,0x51,0x01,0x05,0x7D,0x6E,0x01,0x05,0x85,0x76,0x01,0x05,0x7D,0x70,0x01,0x05,0x7C,0x70,0x01,0x05,0x7C,0x71,0x01,0x05,0x7F,0x73,0x02,0x05,0x7F,0x70,0x01,0x05,0x7F,0x73,0x01,0x05,0x7C,0x70,
0x02,0x00,0x55,0x57,0x01,0x05,0x75,0x77,0x01,0x05,0x7D,0x7E,0x03,0x05,0x74,0x78,0x05,0x05,0x77,0x7B,
0x02,0x00,0x51,0x5A,0x01,0x05,0x6C,0x7F,0x01,0x05,0x75,0x86,0x01,0x05,0x6C,0x7E,0x02,0x05,0x6F,0x81,0x03,0x05,0x6F,0x80,0x02,0x05,0x6F,0x81,
0x02,0x02,0x4A,0x5E,0x01,0x05,0x67,0x84,0x01,0x05,0x6C,0x8F,0x01,0x05,0x67,0x87,0x01,0x02,0x66,0x87,0x01,0x02,0x66,0x86,0x01,0x05,0x66,0x89,0x01,0x05,0x66,0x86,0x01,0x05,0x69,0x86,0x01,0x05,0x66,0x86,0x01,0x05,0x66,0x89,
0x02,0x00,0x44,0x64,0x01,0x02,0x5E,0x8D,0x01,0x05,0x64,0x97,0x02,0x02,0x5E,0x8F,0x01,0x05,0x5E,0x8F,0x02,0x02,0x61,0x8E,0x02,0x05,0x61,0x8E,0x01,0x02,0x61,0x8E,
0x02,0x00,0x3E,0x6B,0x01,0x02,0x59,0x93,0x01,0x02,0x5F,0x9F,0x01,0x02,0x59,0x94,0x07,0x02,0x58,0x97,
0x02,0x00,0x3D,0x6F,0x01,0x02,0x51,0x9B,0x01,0x02,0x57,0xA4,0x01,0x02,0x50,0x9A,0x02,0x02,0x53,0x9D,0x04,0x02,0x53,0x9C,0x01,0x02,0x53,0x9D,
0x02,0x00,0x37,0x75,0x01,0x02,0x4B,0xA0,0x01,0x02,0x4E,0xAD,0x01,0x02,0x4A,0xA3,0x02,0x02,0x4A,0xA2,0x03,0x02,0x4A,0xA5,0x02,0x02,0x4A,0xA2,
0x02,0x00,0x31,0x78,0x01,0x02,0x45,0xA6,0x01,0x02,0x49,0xB2,0x01,0x02,0x42,0xA9,0x01,0x02,0x45,0xAB,0x02,0x02,0x44,0xAB,0x02,0x02,0x45,0xAB,0x01,0x02,0x44,0xAB,0x01,0x02,0x44,0xAA,
0x02,0x00,0x2C,0x7A,0x01,0x03,0x3C,0xAC,0x01,0x02,0x40,0xBB,0x01,0x05,0x3F,0xAF,0x02,0x02,0x3E,0xB1,0x01,0x05,0x3E,0xB1,0x02,0x05,0x3F,0xB1,0x01,0x02,0x3F,0xB1,0x01,0x02,0x3E,0xAE,
0x02,0x00,0x26,0x7E,0x01,0x03,0x36,0xB5,0x01,0x02,0x3A,0xC0,0x01,0x02,0x39,0xB4,0x02,0x02,0x39,0xB7,0x03,0x02,0x39,0xB6,0x02,0x02,0x39,0xB7,
0x02,0x00,0x22,0x86,0x01,0x03,0x30,0xBB,0x01,0x03,0x35,0xC6,0x01,0x03,0x30,0xBD,0x01,0x03,0x30,0xBC,0x04,0x02,0x33,0xBC,0x01,0x02,0x33,0xBF,0x01,0x02,0x33,0xBC,
0x02,0x00,0x1E,0x89,0x01,0x03,0x2A,0xBE,0x01,0x02,0x2E,0xCF,0x01,0x03,0x2A,0xC3,0x01,0x03,0x2D,0xC2,0x01,0x03,0x2D,0xC3,0x02,0x02,0x2D,0xC3,0x01,0x03,0x2D,0xC3,0x02,0x03,0x2D,0xC2,
0x02,0x00,0x1B,0x8F,0x01,0x03,0x27,0xC4,0x01,0x02,0x28,0xD2,0x01,0x03,0x27,0xC9,0x01,0x03,0x26,0xC9,0x01,0x03,0x26,0xC6,0x01,0x02,0x26,0xC9,0x01,0x03,0x26,0xC9,0x02,0x03,0x26,0xC8,0x01,0x03,0x26,0xC9,
0x02,0x00,0x17,0x93,0x01,0x02,0x20,0xCA,0x01,0x03,0x22,0xD8,0x01,0x03,0x20,0xCC,0x04,0x03,0x23,0xCF,0x01,0x03,0x23,0xD1,0x02,0x03,0x20,0xCE,
0x02,0x00,0x15,0x97,0x01,0x03,0x1D,0xCE,0x01,0x03,0x1F,0xDF,0x01,0x03,0x1D,0xD3,0x01,0x03,0x1D,0xD2,0x02,0x03,0x1D,0xD5,0x01,0x03,0x1D,0xD2,0x03,0x03,0x1D,0xD5,
0x02,0x00,0x0E,0x96,0x01,0x03,0x16,0xD5,0x01,0x03,0x19,0xE5,0x01,0x03,0x17,0xD6,0x01,0x03,0x16,0xD9,0x01,0x03,0x17,0xD9,0x01,0x03,0x16,0xD8,0x03,0x03,0x16,0xD9,0x01,0x03,0x16,0xD8,
0x02,0x00,0x0C,0x9A,0x01,0x03,0x13,0xD8,0x01,0x03,0x12,0xE8,0x01,0x03,0x10,0xDA,0x05,0x03,0x13,0xDD,0x01,0x03,0x13,0xDC,0x01,0x03,0x13,0xDD,
0x02,0x00,0x0A,0xAF,0x01,0x03,0x11,0xE5,0x01,0x03,0x11,0xF7,0x07,0x02,0x0E,0xEE,0x01,0x02,0x0E,0xF1,
0x00};
void writeRGB(uint8_t r,uint8_t g,uint8_t b,int nStrip)
{

PaulS

The indenting of that code is horrible. There are no comments that explain what it is supposed to be doing.

Code: [Select]
void loop() {
for(int x=0;x<STRIP_WIDTH;x++) {
uint_farptr_t farptr;
if(x % 100 ==0) {
switch(x / 100) {
case 0:
farptr=GET_FAR_ADDRESS(bitmap_0);
break;
}

X modulo 100 will be 0 when x is 0, 100, 200, etc. However, the loop only runs for 44 iterations, so the only value for x for which x%100 will be 0 is x=0. Why you use a switch statement with one case is a mystery. The magic number 100 is unexplained.

Really, there is far too much unexplained, poorly arranged, magic stuff happening here to make heads or tails of. I think you need to start over.
The art of getting good answers lies in asking good questions.

moyzie

PaulS:
I am totally new to this code writing and so I downloaded a little program, the program that I posted a link to is what created the code here. I have been trying to find out how to write it myself but not having much luck.


"With this code all I am getting is the first LED lighting in a green colour. It should be all 12 fading green to blue over 30 secs I can't find why there is only one led lighting the others are all just white with no change."
that is what is supposed to be happening.


nickgammon

What does this do?

Code: [Select]

#define GET_FAR_ADDRESS(var) \
({ \
uint_farptr_t tmp; \
__asm__ __volatile__( \
"ldi    %A0, lo8(%1)"  "\n\t"    \
"ldi    %B0, hi8(%1)"  "\n\t"    \
"ldi    %C0, hh8(%1)"  "\n\t"    \
"clr    %D0"  "\n\t"    \
: \
"=d" (tmp) \
: \
"p"  (&(var)) \
);   \
tmp; \
})
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

moyzie


What does this do?

Code: [Select]

#define GET_FAR_ADDRESS(var) \
({ \
uint_farptr_t tmp; \
__asm__ __volatile__( \
"ldi    %A0, lo8(%1)"  "\n\t"    \
"ldi    %B0, hi8(%1)"  "\n\t"    \
"ldi    %C0, hh8(%1)"  "\n\t"    \
"clr    %D0"  "\n\t"    \
: \
"=d" (tmp) \
: \
"p"  (&(var)) \
);   \
tmp; \
})



I have no idea!
the program that generated the code also does code for the led strips may be something related to those
where I am just using the 12mm WS2801 RGB led like this http://www.flickr.com/photos/txross/7355904558/in/set-72157624495736989/
which the programme also creates code for

moyzie

SSSOOO!!! I found out what my problem was with this project with some google research.
I bought some cheap chinese WS2801's from ebay and they were full of shorts and bad pc boards aparently so I went and got the correct ones that were suggested on the webpage that I was creating this project from and now they work perfectly but now I have a problem with battery power
see post http://arduino.cc/forum/index.php/topic,142406.msg1069467.html#msg1069467

Go Up