Show Posts
Pages: 1 ... 15 16 [17] 18 19 ... 67
241  Using Arduino / Programming Questions / Re: This code works but there must be a better/more elegant way on: April 17, 2013, 08:39:57 am
Perhaps it will help to make the issue explicit.  Please compare this creative use of the ',' syntax, which happens to compile but does not do what you think it does:
Code:
if (ChCount == 9, ChCount = 1);

and this, which would do what you want:
Code:
if (ChCount == 9) ChCount = 1;

See the difference?

Add "C comma operator" to your list of stuff to learn about.  In this case, to avoid, mostly.

-br
242  Using Arduino / Programming Questions / Re: operating sine wave equation in Arduino on: April 17, 2013, 07:06:17 am
Your debugging will go much better if you print out the key values so you can see when they leave the tracks and deduce what is driving it.

It looks like there is an awful lot of integer arithmetic going on inside that big expression calculating pos1.  You might find it works better if you make all the constants and variables participating in that calculation floating point.  Put ".0" after the integer-looking constants, at least.

-br
243  Using Arduino / Interfacing w/ Software on the Computer / Re: Duemillanove - Scheduling on: April 17, 2013, 06:58:37 am
If you really want 1ms rates and pre-emption you need to be thinking about interrupts.

If something more like 5-20ms granularity with cooperative run-to-completion scheduling is acceptable, here's a library:

https://github.com/billroy/run

-br
244  Using Arduino / Programming Questions / Re: This code works but there must be a better/more elegant way on: April 17, 2013, 06:54:22 am
This would be a good place to use an "array of structs".  

A struct is a collection of variables that you can treat as a unit.  You could use a struct to represent a channel, with a byte for the channel id, a char* for the name, a float for the value, and so on.

You could then set up a (constant) array of these structs to represent your list of channels.  A particular channel would be specified by the index into the array, a small integer to select the channel.

Then you can simplify your code by replacing all the lengthy per-channel setups with a call to a single function, passing the struct index for the desired channel, that would set up the desired properties like the per-channel setups do now.

Does that make any sense?

-br
245  Using Arduino / Programming Questions / Re: ASCII to int (yes, another one) on: April 16, 2013, 05:45:44 pm
Love a little code golf:

Code:
int gethex(byte which) {
char c = buff[which];
if ((c >= '0') && (c <= '9')) return c - '0'
c = toUpper(c);
if ((c >= 'A') && (c <= 'F')) return c - 'A' + 10;
return 0;
}

...
int red =   (gethex(0) << 4) + gethex(1);
int green = (gethex(2) << 4) + gethex(3);
int blue =  (gethex(4) << 4) + gethex(5);


-br
246  Using Arduino / Project Guidance / Re: CSS sheet via println? on: April 16, 2013, 06:46:05 am
Do the styles work correctly if you save the generated HTML and open the HTML file in a browser? 

If they don't, good for you -- you can debug it with a browser and then back-port the fixes to your Arduino code.

-br
247  Using Arduino / Project Guidance / Re: Web server controled pins - what is the best method? on: April 16, 2013, 06:41:23 am
You asked about Bitlash Commander examples: I keep a copy running at http://bitlash-commander.herokuapp.com if you'd like to kick the tires without an Arduino attached.

-br

248  Using Arduino / Project Guidance / Re: All pins show ground on: April 15, 2013, 07:46:57 am
Did you have a reason to expect something different?

-br
249  Using Arduino / Programming Questions / Re: Int Loop - Noob Question on: April 14, 2013, 06:34:49 pm
Globals are only initialized (by default to zero) once at initialization time, before setup() is called.

If you want to reinitialize a variable at the top of the loop() function, just assign it yourself in the usual way.

-br
250  Using Arduino / Project Guidance / Re: Web server controled pins - what is the best method? on: April 14, 2013, 06:29:07 pm
Well I'm biased, because I wrote a PC-based web control panel server which you can read about here:  https://github.com/billroy/bitlash-commander

Both approaches are workable.  It kind of depends on the tools you like to work with.

-br
251  Using Arduino / Programming Questions / Re: Beginning Code Error Message on: April 14, 2013, 06:25:27 pm
That code breaks here for a different reason: TABLE_ENTRIES is not defined.

If you share the actual code that generated that error you might get better help.

-br
252  Using Arduino / Networking, Protocols, and Devices / Re: HTTP GET Request results in 400 Bad Request on: April 14, 2013, 03:48:46 pm
What does the error log on the hosting side say?  It may have a clue why that URL isn't correct.

-br
253  Using Arduino / Programming Questions / Re: unknown message on: April 14, 2013, 09:11:09 am
That code works fine here (tested on serial monitor) on an old Duemilanove with a '328.

What kind of Arduino do you have?

-br
254  Using Arduino / Programming Questions / Re: unknown message on: April 14, 2013, 08:26:35 am
It would be helpful to see exactly what text is sent…

-br
255  Using Arduino / Programming Questions / Re: unknown message on: April 14, 2013, 08:17:59 am
I don't see your bug yet, unless you send more than 10 characters between angle brackets.  

But there is a bug in such a case: if you send more than 9 characters you'll overflow the inData buffer and overwrite index, which is the sort of thing that can lead to the weird behavior you're seeing.  

It's best to check to see if there's room in a buffer before adding a character to it.

-br
Pages: 1 ... 15 16 [17] 18 19 ... 67