Page 1 of 1

LED Matrix: Create the American Flag in a LED matrix

LED Matrix: Create the American Flag in a LED matrix

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.




RSS Feed

Home Forums Hardware Arduino LED Matrix: Create the American Flag in a LED matrix

This topic contains 4 replies, has 3 voices, and was last updated by  hans 6 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • 7530

    hans
    Keymaster

    This topic was started based on a request by ‘Cam’ who was looking for example code to create an American flag in a LED matrix, using WS2812 LED strips and an Arduino. See this comment under the Arduino WS2812 article.

    7532

    hans
    Keymaster

    OK, so for this topic I assume that Arduino, LED strip etc work.
    Make sure you’ve gone that route before starting to read these posts (to get started: Arduino and WS2812 and LED Strip Effects).

    The LED Strip Effects article is a good one to take as a base, so the user can pick either FastLED of NeoPixel …

    To make a flag with a matrix, I’ll assume that we use 3 colors: Red, White and Blue. 
    Now I’ll make it so that other flags hopefully can be made this way as well so be aware that there are more efficient ways of doing this, depending on the flag of your choice.

    First we will define the colors, in this case 3 colors: red, white and blue (see more about arrays for Arduino).

    byte Color1[3] = { 0xFF, 0x00, 0x00 }; // Define color 1 as red (RGB)
    byte Color2[3] = { 0xFF, 0xFF, 0xFF }; // Define color 2 as white (RGB)
    byte Color3[3] = { 0x00, 0x00, 0xFF }; // Define color 3 as blue (RGB)  

    Next we create a matrix for the flag, where we use “1” for Color1, “2” for Color2, and “3” for Color3.
    Our matrix will be 30 columns (X) and 8 rows (Y) – but feel free to modify this later on …
    I know this looks confusing since I’m swapping X and Y in the array, it does however help when you’re defining the array:

    byte FlagColors[8][30] = { { 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                               { 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                               { 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 
                               { 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                               { 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                               { 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                               { 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                               { 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }; 

    Now here I run into problem number 1 … 

    First of all, to be able to display the American flag, I’d need at least 13 rows (red/white bars), and you’ve chose to use only 8.
    Next problem is displaying the stars.  If we want to depict every star, we’d need 9 rows for that.

    Combining the two would at least require 15 rows … the first 9 would be needed for a crude way of displaying the stars, but when we look at the American flag, you’ll see that there are 6 more rows needed to complete the horizontal red/white stripes.

    So my first question are:

    If we stick to 30 columns and 8 rows, how would you fill in the matrix (see above)?
    Or would you prefer to start using more rows?

    Attachments:
    You must be logged in to view attached files.
    7538

    maxxgold
    Participant

    First of all let me say thank you very much, your help is greatly appreciated!

    I’m not concerned with the proportions of the matrix that I have created. I just separated the WS2812 strip at the solder joints to make things easier. Once I get a good understanding of how to do this on my own I plan to order some more LEDS and create a enclosure for a more proportionate flag. So right now the 30x x 8y matrix will work for me. 

    I completely understand that you have assigned the colors to the numbers 1,2, and 3 to use in the matrix you have created, and I understand the matrix. I have taken calculus so I understand the math, I have just never used it for programming.

    I’m going to look at the link you posted for arrays, and I’m going to start in on your course!

    7544

    cam
    Participant

    Hey,

    It definitely wasn’t me  I’m not american and I’m not a patriot (as a clue to where I’m from… )

    7548

    hans
    Keymaster

    @maxxgold; OK, let me know where I can help – I’d be happy to! 

    @cam; Yeah I’m not American either, but … I live there at the moment though 

Viewing 5 posts - 1 through 5 (of 5 total)



You must be logged in to reply to this topic.