Breaking News
Comments
Newest First | Oldest First | Threaded View
Page 1 / 3   >   >>
Max The Magnificent
User Rank
Blogger
Re: Simplest
Max The Magnificent   10/28/2013 4:46:34 PM
NO RATINGS
@jpessin: It's probably not the most efficient option computationally, but perhaps the simplest solution would be to use the Arduino language's map() function.

This just goes to show that I really need to spend some time on the Arduino website looking to see what's there. I'm currently ver yhappy with the solution proposed by Javi (Garcia) earlier in these comments, but it's great to know that this (and other) functions are available.

 

Max The Magnificent
User Rank
Blogger
Re: Distance calculation ...
Max The Magnificent   10/28/2013 4:41:18 PM
NO RATINGS
@Bastian.Schick: In the ancient times we used a modified Bresenham algorithm to fade between colours...

You make it sound as though you are talking about the last millennium .... Oh, wait a moment... LOL

Max The Magnificent
User Rank
Blogger
Re: Use fractions
Max The Magnificent   10/28/2013 4:39:53 PM
NO RATINGS
@another nickname: Your truncation problem would not be there if you stick with fractions.

True enough -- but the problem also goes away if we use the solution proposed by Javi (Garcia) in the early comments to this blog.

Max The Magnificent
User Rank
Blogger
Re: Rounding integer division
Max The Magnificent   10/28/2013 4:38:12 PM
NO RATINGS
@DU0...01: Though the Bresenham algorithm might be appropriate...

I know this is not complex -- but I can imagine the problems that woudl ensue trying to explain all of this to an absolute beginner :-)

jpessin
User Rank
Rookie
Simplest
jpessin   10/28/2013 4:26:42 PM
NO RATINGS
It's probably not the most efficient option computationally, but perhaps the simplest solution would be to use the Arduino language's map() function.  It seems to work going up and going down in color value, and ends on exactly the right value, in the right number of steps.

http://arduino.cc/en/Reference/Map

 

This gives:

void lightLEDs (int howMany,
                int howLong)
{
    for (int i = 1; i <= howMany; i++)
    {
        int tmpColor = map(i, 0, howMany, oldColor, newColor);

        // Use current tmpColor to drive LED

        delay(howLong);
    }
}

Bastian.Schick
User Rank
Rookie
Re: Bresenham algorithm
Bastian.Schick   10/27/2013 2:50:53 AM
NO RATINGS
Sorry I did double this. But yes, Bresenham is the IMHO the best choice to move in descrete steps from one point to another.

Bastian.Schick
User Rank
Rookie
Distance calculation ...
Bastian.Schick   10/27/2013 2:49:14 AM
NO RATINGS
Two things:
- The distance between 0 and 255 is (255-0)+1

- In the ancient times we used a modified Bresenham algorithm to fade between colours.


Cheers

another nickname
User Rank
Rookie
Use fractions
another nickname   10/26/2013 8:29:22 PM
NO RATINGS
Your truncation problem would not be there if you stick with fractions.

Just keep 2 integers for each number numerator and denominator) and rewrite your algorithm using 2 numbers instead of one for all calcluations and do multiplications first and divisions last. It's pretty much the same as Fixed Point arithmetics .

DU00000001
User Rank
CEO
Rounding integer division
DU00000001   10/26/2013 7:18:27 PM
NO RATINGS
Though the Bresenham algorithm might be appropriate, the initial question was how to cope with the truncating element of the integer division.

The solution is really simple:

result = (dividend + (divisor/2))/divisor   or
result = (dividend + (divisor>>1))/divisor

This might lead us to the next level of discussion: what if divisor is odd?

You simply have to decide whether you want to round up (x.5 => x+1) or down (x.5 => x). In one of the cases the above equations will read ((divisor+1)/2) resp. ((divisor+1)>>1).

There's always a last philosophical question or, in other words, the freedom of choice :)

Max The Magnificent
User Rank
Blogger
Re: Bresenham algorithm
Max The Magnificent   10/26/2013 6:01:09 PM
NO RATINGS
@pviry750: The standard way to do this efficiently is the Bresenham algorithm...

Cool beans -- I will bounce over to peruse and ponder the Wikipedia page on this -- I'm sure I will be doing a lot more of this in the future -- for example, with regard to my current robot project.

Page 1 / 3   >   >>


Flash Poll
EE Life
Frankenstein's Fix, Teardowns, Sideshows, Design Contests, Reader Content & More
Max Maxfield

MSGEQ7-Based DIY Audio Spectrum Analyzer: Testing
Max Maxfield
9 comments
In my previous column on this topic, we discussed the step-by-step construction of the first pass at a MSGEQ7-based DIY audio spectrum analyzer for use in my BADASS Display project. Of ...

Karen Field

June 2014 Cartoon Caption Winner
Karen Field
13 comments
Congratulations to "Wnderer" for submitting the winning caption for our June cartoon, after much heated conversation by our judges, given the plethora of great entries.

Jeremy Cook

Inspection Rejection: Why More Is Less in a Vision System
Jeremy Cook
3 comments
Albert Einstein has been quoted as saying, "Everything should be as simple as possible, but not simpler." I would never claim to have his level of insight -- or such an awesome head of ...

Jeremy Cook

Machine Fixes That Made Me Go 'DUH!'
Jeremy Cook
21 comments
As you can see in my bio at the end of this article, I work as a manufacturing engineer. One of my favorite things that happens on a Friday late in the afternoon is to hear my phone ring ...

Top Comments of the Week
Like Us on Facebook
EE Times on Twitter
EE Times Twitter Feed

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)