Global Sources
EE Times AsiaWebsite
Stay in touch with EE Times Asia
eeBlogs-Article content Home / eeBlog / eeBlogs
Nickname: Clive Maxfield     Articles(444)     Visits(533505)     Comments(79)     Votes(236)     RSS
There is so much amazingly cool "stuff" to see and do that I'm amazed I find the time to get any real work done. In my blog I will waffle on about the books I'm reading, the projects I'm building, and the weird and wonderful websites I blunder across. Please Email Me if you see anything you think will "tickle my fancy."
Blog Archive
2016 -  Apr.,   Mar.,   Feb.,   Jan.  
2015 -  Dec.,   Nov.,   Oct.,   Sep.,   Aug.,   Jul.,   Jun.,   May.,   Apr.,   Mar.,   Feb.,   Jan.  
2014 -  Dec.,   Nov.,   Oct.,   Sep.,   Aug.,   Jul.,   Jun.,   May.,   Apr.,   Mar.,   Feb.,   Jan.  
View All
Comment | Add to Favorites

Posted: 04:07:53 PM, 02/05/2014

The subtleties of pointers


Several weeks ago I read Jack Ganssle's blog about a book called Understanding and Using C Pointers by Richard M. Reese. I'm a hardware design engineer by trade. The best you can say is that I dabble in the software side of things. The subtleties of pointers have long confused me, so I decided to purchase this book.


Personally, I think this book is well worth the price if you want to move beyond the "training wheel" stage of C programming. I learned a lot. Unfortunately, I didn’t learn as much as I thought I'd learned, because I cannot wrap my brain around a programming problem.


Here's the deal. This all pertains to my current BADASS Display project, which -- as you will doubtless recall -- is going to feature a 16x16 array of tri-colored LEDs as illustrated below.



I'm actually using Adafruit's NeoPixel Strips for this little beauty, with the control of the display being performed by an Arduino Mega microcontroller development board.


I'm planning on using 16 NeoPixel strips, each containing 16 pixels, and each implementing one of the vertical columns in the array. The idea is to take an audio stream from my iPad, split out its spectral components into sixteen frequency "buckets," and then present the results in spectrum-analyzer-form on my display. (I'm still pondering how to extract the frequency spectrum data from the audio stream, but that's a problem for another day.)


Purely for the sake of discussion, let's assume that my NeoPixel strips are named "strip[0]," "strip[1],"… "strip[15]." Meanwhile, the lowest LED (i.e., the one nearest to the bottom of the array) on each strip is numbered 0, while the highest LED is numbered 15. Let's further assume that whatever is processing my audio stream, it generates a series of sixteen five-bit values called "bucket[0]," "bucket[1],"… "bucket[15]." Each of these five-bit values represents the current amplitude associated with that bucket, from 000002 (no LEDS lit) to 100002 (all LEDs lit).


Actually, my previous statement is not strictly true, because these five-bit values actually represent the number of the highest (vertically speaking) LED being lit. The way in which we subsequently display this information depends on what we wish to do -- we could display a solid bar of LEDs from LED 0 up to and including the LED in question, or we could simply light up this topmost LED, or… the list goes on.


But we are wandering off into the weeds. What I would ideally like to do is to have a function called "lightStrip()" that I can call from the main body of my program. Perhaps something like the following:



But then we come to the way in which the folks at Adafruit have created their libraries and instantiate their NeoPixel strips. I think this is done in C++, but -- thankfully -- the gory details are hidden from me. A stripped-down version of the instantiation might look something like the following:



The first parameter is the number of pixels in your strip (16 in this case), while the second parameter is the number of the digital I/O pin you wish to use to drive this strip (1 in this case).


Later on, in the body of your code, you can use calls like the following:



In the case of the "strip.setPixelColor()" function call, "i" is the number of the pixel (ranging from 0 to 15 in our case) whose color you wish to specify using three eight-bit values for the red, green, and blue channels. The interesting thing is that the "strip.setPixelColor()" function doesn’t actually drive the strip itself. It just stores the new color values in an array in memory. This means you can specify the color values of any and all elements in the strip without actually writing to the strip each time.


Once we have all of our ducks in a row, as it were, we use the "" function to upload all of the color values into the strip. Now, we can instantiate multiple strips called "strip0," "strip1," "strip2," and so forth if we wish. But this is where I grind to a halt. How can I pass these different strips into my "lightStrip()" function? I know that in regular C it's possible to pass a pointer to one function as an argument into another function, but how does that relate to what I'm talking about here? All I can say is that any thoughts you care to share will be very gratefully received.

Views(621) Comments(0)
Total [0] users voted     
[Last update: 04:07:53 PM, 02/05/2014]
Have Your Say!

Bloggers Say

Got something to say? Why not share it with other engineers?

Just introduce yourself to us, we'll contact you and set you up. Yes, it's that simple!

See what engineers like you are posting on our pages.


• Modern-day engineering notebooks
Posted:21/01/16 05:50 PM
• Meetings will persist until morale ...
Posted:28/08/15 10:09 PM

• LCD inventor shook things up at DAR...
Posted:07/12/12 10:32 AM
• Robotics passion inspires Android c...
Posted:29/11/12 04:38 PM

• Platform-independent way to generat...
Posted:02/10/15 06:21 PM
• Yes, phone market can still grow
Posted:11/09/15 08:57 PM

• Further on IoT opportunities for se...
Posted:05/05/15 03:18 PM
• New opportunities for Singapore sem...
Posted:16/02/15 06:21 PM
Interviews & Viewpoints


Learn how senior executives are seeing the industry from interviews and contributed opinions.

Back to Top