Loading...
  Show Posts
Pages: [1]
1  Using Arduino / LEDs and Multiplexing / Re: 595 patterns on: January 11, 2013, 03:30:03 pm
Thanks for confirming my suspicion. I appreciate your feedback.

I seem to learn best by trial and error, also known as fumbling around !

I am a disabled veteran. One thing I have a lot of is time.

Programming helps take my mind off of negative things.
2  Using Arduino / LEDs and Multiplexing / Re: 595 patterns on: January 11, 2013, 11:22:33 am
Thanks for your reply.

I narrowed my issue somewhat.
When sizeof() is used directly on an array, it returns the correct size.

However, when I pass an array to a function THEN use sizeof(), it returns 2.
I am thinking that sizeof() is returning the size of the pointer. Not sure about this.

Reading online C tutorials concerning passing arrays to functions, they say in passing an array
to a function you are in fact passing a pointer. Still learning about pointers.

My goal is for this program to receive a single input using a keypad or button to input a pattern selection.
Currently, I am modifying my code so the input function will take a number, in a limited range, using switch . . . case.
Switch . . . case  assigns a pointer to the specified pattern array, sizes the array then passes pointer and size to the output function.

As I stated in a previous post, I am new to this programming language.

I am having so much fun learning this language.
I can see so many possibilities that were not available when I was using various flavors of Basic.

Thanks again for your help!

Paul
3  Using Arduino / LEDs and Multiplexing / Re: 595 patterns on: January 10, 2013, 09:03:29 pm
I constructed my patterns in binary first, then convert to hex.
I got tired of scrolling thru lines of data.
Using hex data only saves space in your code, not the compiled sketch.

Example:

  data[] = {0000 0000,  // =  0x00
                1000 0001,  // =  0x81
                0100 0010,  // =  0x42
                0010 0100,  // =  0x24
                0001 1000,  // =  0x18
                . . . . . . . .}

  data[] = {0x00,0x81,0x42,0x24,0x18, . . };
 
  Some of my patterns have 30 elements.

  One line of data versus 32 lines makes easier code reading.

4  Using Arduino / LEDs and Multiplexing / Re: 595 patterns on: January 10, 2013, 07:01:49 pm
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 !!
Code:
//======================= 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
}
//-----------------------------------------------------------------------------


Pages: [1]