Hi everyone!
I am new to Arduino and this Forum. I am retired military and like to program uMicroProcessors & build robots/projects
that actually do something. Who says you can't teach an old dog new tricks!
I have been working on a project very similar to this thread. Using 74HC595 shift register to control Christmas lights.
I had already written programs in Basic for other uProcessors, so I have been trying to port those programs to Arduino.
I have not worked with C before, so this has been very interesting.
My goal is to construct very small control units to control multiple strings of LED Christmas lights.
Attached is one of my first sketch to implement this goal. ( It functions properly. )
For testing, I have the shift register connected to 8 LEDs of a 10 LED bar graph, so I can visualize the patterns.
I have also tested this sketch with my relay boards.
In this sketch, I pass a pattern array, and its size, to a function for display through a shift register.
I have been trying to use the utility function 'sizeof()' without success.
Every time I have used 'sizeof()', it returns the value '2' regardless of the size of the array.
The C programming tutorials that I have been studying says in passing an array to a function, you need to pass the size of the array as well.
Am I missing something? Is there a issue with 'sizeof()' ?
Could someone show me an example of proper use of 'sizeof()' that actually returns the correct size of an array?
If I can get 'sizeof()' to work, I can simplify my function & sketch.
I apologize in advance for any breach of protocol. Just let me know what I need to do to comply with Forum standards.
P.S. I Love this stuff !!
//======================= this line is 80 chars long ==========================
//-----------------------------------------------------------------------------
/*
Program Name: _74HC595
Author: Paul Fogle
Date: 01/05/2013
Modified: 01/10/2013
Goal: Use 74HC595 shift register to control Christmas light relays.
Input pattern array number and pass to ChristmasLightRelay()
function .
*/
//-----------------------------------------------------------------------------
byte Pattern_0[2] = {0xAA, 0x55};
// every other, alternate
byte Pattern_1[4] = {0x18,0x24,0x42,0x81};
// middle out
byte Pattern_2[6] = {0x81,0x42,0x24,0x18,0x24,0x42};
// ends to middle, bounce single
byte Pattern_3[9] = {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
// left to right, all on repeat
byte Pattern_4[15] = {0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x7f,0x3f,
0x1f,0x0f,0x07,0x03,0x01};
// left to right, all on exit right
byte Pattern_5[15] = {0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,0xfe,0xfc,0xf8,
0xf0,0xe0,0xc0,0x80};
// opposite of Pattern 4
byte Pattern_6[30] = {0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x7f,0x3f,0x1f,
0x0f,0x07,0x03,0x01,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,
0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80};
// left to right bounce right to left
byte Pattern_7[7] = {0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81};
// ends to middle, all on
//-----------------------------------------------------------------------------
byte sizePattern_0 = 2; // size of pattern 0
byte sizePattern_1 = 4; // size of pattern 1
byte sizePattern_2 = 6; // size of pattern 2
byte sizePattern_3 = 9; // size of pattern 3
byte sizePattern_4 = 15; // size of pattern 4
byte sizePattern_5 = 15; // size of pattern 5
byte sizePattern_6 = 30; // size of pattern 6
byte sizePattern_7 = 7; // size of pattern 7
int delayDur = 150; // display speed in light pattern
int latchpin = 8; // green connect to pin 12 on shift register
int clockpin = 12; // white connect to pin 11 on shift register
int datapin = 11; // black connect to pin 14 on shift register
//-----------------------------------------------------------------------------
void setup()
{
Serial.begin(9600); // com to computer
Serial1.begin(9600); // pin 18 ModernDevice Lcd
pinMode(latchpin, OUTPUT); // pin 12, shift register
pinMode(clockpin, OUTPUT); // pin 11, shift register
pinMode(datapin, OUTPUT); // pin 14, shift register
SetupLcd();
}
//-----------------------------------------------------------------------------
void loop()
{
LightRelay(Pattern_6, sizePattern_6); // call function to output pattern
}
//-----------------------------------------------------------------------------
// I have tried to use the sizeof() utility without success, it always returns
// 2 on every array that I have tried, so I pass a size variable (tempSize) to
// the function.
//
//
void LightRelay(byte *temp, byte tempSize) // output pattern to shift register
{ for (byte x = 0; x < tempSize; x++)
{
digitalWrite(latchpin, LOW); // enable data write
shiftOut(datapin, clockpin, MSBFIRST, temp[x]); // data write
digitalWrite(latchpin, HIGH); // disable data write
delay(delayDur); // display speed
Serial1.print("?x00?y0Size of array: ?x15"); // print to lcd
Serial1.print(tempSize); // print to lcd
}
}
//-----------------------------------------------------------------------------
void SetupLcd()
{
Serial1.print("?G420?c0?f?x05?y3HELLO PAUL"); // print to lcd
delay(2000); // pause so I can read my name
}
//-----------------------------------------------------------------------------