Design Con 2015
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   >   >>


Top Comments of the Week
Flash Poll
Like Us on Facebook

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
EE Life
Frankenstein's Fix, Teardowns, Sideshows, Design Contests, Reader Content & More
Max Maxfield

Max's BADASS Display: A Comedy of Errors
Max Maxfield
3 comments
Good grief -- where does the time go? I first determined to build my Bodacious Acoustic Diagnostic Astoundingly Superior Spectromatic (BADASS) display way back in the mists of time we used ...

<b><a href=Betajet">

The Circle – The Future's Imperfect in the Present Tense
Betajet
5 comments
The Circle, a satirical, dystopian novel published in 2013 by San Francisco-based writer Dave Eggers, is about a large, very powerful technology company that combines aspects of Google, ...

Martin Rowe

Make This Engineering Museum a Reality
Martin Rowe
Post a comment
Vincent Valentine is a man on a mission. He wants to make the first house to ever have a telephone into a telephone museum. Without help, it may not happen.

Rich Quinnell

Making the Grade in Industrial Design
Rich Quinnell
16 comments
As every developer knows, there are the paper specifications for a product design, and then there are the real requirements. The paper specs are dry, bland, and rigidly numeric, making ...

Special Video Section
The LT8640 is a 42V, 5A synchronous step-down regulator ...
The LTC2000 high-speed DAC has low noise and excellent ...
How do you protect the load and ensure output continues to ...
General-purpose DACs have applications in instrumentation, ...
Linear Technology demonstrates its latest measurement ...
10:29
Demos from Maxim Integrated at Electronica 2014 show ...
Bosch CEO Stefan Finkbeiner shows off latest combo and ...
STMicroelectronics demoed this simple gesture control ...
Keysight shows you what signals lurk in real-time at 510MHz ...
TE Connectivity's clear-plastic, full-size model car shows ...
Why culture makes Linear Tech a winner.
Recently formed Architects of Modern Power consortium ...
Specially modified Corvette C7 Stingray responds to ex Indy ...
Avago’s ACPL-K30T is the first solid-state driver qualified ...
NXP launches its line of multi-gate, multifunction, ...
Doug Bailey, VP of marketing at Power Integrations, gives a ...
See how to ease software bring-up with DesignWare IP ...
DesignWare IP Prototyping Kits enable fast software ...
This video explores the LT3086, a new member of our LDO+ ...
In today’s modern electronic systems, the need for power ...