Embedded Systems Conference
Breaking News
Comments
Newest First | Oldest First | Threaded View
Page 1 / 3   >   >>
Max The Magnificent
User Rank
Author
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
Author
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
Author
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
Author
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
Author
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
Author
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
Author
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
Author
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
Author
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
Author
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   >   >>


Radio
NEXT UPCOMING BROADCAST
IoT Network Shoot Out
July 16, 1pm EDT Thursday

Replay available now: A handful of emerging network technologies are competing to be the preferred wide-area connection for the Internet of Things. All claim lower costs and power use than cellular but none have wide deployment yet. Listen in as proponents of leading contenders make their case to be the metro or national IoT network of the future. Rick Merritt, EE Times Silicon Valley Bureau Chief, moderators this discussion. Join in and ask his guests questions.

Brought to you by

Most Recent Comments
vasanth kumar d
 
scud
 
realjjj
 
DN@
 
AKH0
 
michigan0
 
MeasurementBlues
 
michigan0
 
Kevin Neilson
Flash Poll
Top Comments of the Week
Like Us on Facebook

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
Special Video Section
Chwan-Jye Foo (C.J Foo), product marketing manager for ...
The LT®3752/LT3752-1 are current mode PWM controllers ...
LED lighting is an important feature in today’s and future ...
Active balancing of series connected battery stacks exists ...
After a four-year absence, Infineon returns to Mobile World ...
A laptop’s 65-watt adapter can be made 6 times smaller and ...
An industry network should have device and data security at ...
The LTC2975 is a four-channel PMBus Power System Manager ...
In this video, a new high speed CMOS output comparator ...
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.