Go Down

Topic: Programming ??? Math Question (Read 1 time) previous topic - next topic


@PaulS: Are the numbers you list really the ones you came up with. When I walk through the code I does get decimal values that need to be rounded but none are as high as 92? I might be miss calculating?

No, I was trying to make two points. First, I don't see any sanity checking of the input data. That's usually a good idea. Second, I don't understand why the inputs are floats. Don't the line ends correspond to positions where the LEDs are located in the matrix? Aren't the LEDs uniformly spaced? That is, at 0, 1, 2, etc., rather than 0.1, 1.3, 2.7, etc.


Hello thanks again or the replies.

I am an experienced developer but I am new to Arduino style programming. I see now from the replies that I really have to look in to better ways to debug. I assumed that since the code runs on the Arduino I could not use the debug area at the bottom of the development environment. I'll look in to Serial.Print as suggested.

Also there were some questions about why I used floats. Depending on the angle of the line I my be incrementing it by very small values each cycle. For example a line that starts on one row and ends on the next will increment about 0.2 each time. The .2 is not really important but if you throw it out you will never get the next row.

I could have limited my use of floats to the number I am incrementing but I have found in some languages that if you mix in even one integer the answer could be rounded to integer. Not sure how Arduino does it but I was trying to get the right answer before I started improving the code. I hope to get the hang of these Arduino C++ nuances.

Thanks again everyone!!
Dave G


Are you using the Arduino IDE ?
If so, then Serial.print sends it output to the IDE's Serial monitor or another serial device listening on the COM port that the USB interface creates.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


@UKHeliBob: I am use the IDE. For some reason I didn't think it would be that easy. I thought I would have to write sending and receiving code. I'll give it a shot when I get home tonight.

The more I learn about my Arduino the more I am pleasantly surprised. :)


Hello All,

This is my first post and I am happy to be using Arduino!!!

I recently built an 8x8x8 rgb led cube. Well almost done, I have two 8x8 towers going and I am having some fun turning independent LEDs on and off. Now I am trying to write some more advanced graphic routines to turn on more then single LEDs. For example lines and circles. I just can't seem to get the line rountine to work. Any help would be appreciated.

Check out this link: http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

That's Bresenham's line draw algorithm. It's used in any graphics code that draws a line from one point to another.

Working with a cube, you have a THREE dimensional space to work with. You may wish to divide the cube into two parallel square planes, one located at the line start and the other at the line end. Then distance between the planes is the line length and the X/Y coordinates in each plane locate the start and end point. Then, use Bresenham to calculate all the points in between.

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Go Up