3-bit Counter - Using solely (nested) for loops
Show older comments
Hi there,
I am trying to write a way to create an 3 column 8-bit RGB array to capture all 15 million+ possible colors - without storing the values, dynamically on an arduino (end code will be in C). I want to approach this problem by scaling down and using a language I am comfortable with - i.e. MATLAB.
So I want to understand a very rudimentary 3 bit counter, 2^3 = 8 rows, 3 columns - without using MATLAB's inbulit flipud, or dec2bin functions.
Only nested for loops.
What is the most logical way of approaching this problem? There will be a pattern of numbers always recurring in a sequence set by the column value as shown below - is it smart to utilize this sequence? I would really appreciate any pointers!
**I believe this problem (with regards to the RGB matrix) is documented, however, I want to exhaust all possible methods to do it by myself - before looking up resources
4 2 1 repitition (2^col)
______
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
4 Comments
It's been forever since I used Matlab to write code for AVR, but I was never comfortable with the ambiguity and overhead that came with it. Not knowing how it's going to try to compile, couldn't you just make a simple incrementing loop operating on a uint8 scalar? You're going to be occupying an entire 8 bits anyway, even if you only use the first 3 on the output. I don't see the reason to try to nest anything or treat the bits as separate numbers within the counter.
Rik
on 5 Apr 2021
I don't understand what you want to do exactly. Do you want code that produces the entire 3x16777216 array?
mod might be helpful in some way, depending on what you want to do exactly.
Okay, I misunderstood what you're trying to do. I thought you were trying to make a 3-bit counter by incrementing three unique 1-bit numbers. You're actually dealing with columns of 8-bit numbers. Sorry. I guess that makes more sense.
I guess it's be better to call it a 3-digit base-256 counter ... but they aren't really "digits"
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!