Show Posts
|
|
Pages: 1 2 3 [4] 5 6 ... 66
|
|
46
|
Using Arduino / Project Guidance / Re: Newbie needing help
|
on: May 06, 2013, 06:28:29 am
|
|
In my view, the best way to learn fast is to read a lot of other people's code. You won't necessarily understand it all, at first, but that's good, and easily fixed with google.
You can find a lot of code here on the forum and playground, and don't overlook GitHub where some of the bigger projects live.
Just my two cents. Good luck with your learning process.
-br
|
|
|
|
|
48
|
Using Arduino / Project Guidance / Re: Scheduling cooperative tasks waiting on a delay.
|
on: May 05, 2013, 08:27:19 pm
|
This library replicates the task scheduler from Bitlash for Arduino C functions: https://github.com/billroy/runSimple non-pre-emptive round-robin scheduling seems to be tunable to more or less work in most of the cases I've seen. But I wouldn't expect to run a lot of 5-20 ms tasks. In Bitlash, the keyboard response stays pretty lively until the fastest intertask interval goes below about 50ms. Simple tasks (in Bitlash) run fine down into the 10-20 ms range, at which point you're basically running the task every time through the scheduler. -br
|
|
|
|
|
49
|
Using Arduino / Programming Questions / Re: "Hourglass" without delay - understanding if, while, & for loops
|
on: May 05, 2013, 08:11:17 pm
|
|
You are not guaranteed to see every millisecond via millis(); sometimes it skips one, which would botch your % 60000 scheme, wouldn't it?
It would be much more reliable to use the difference in time, instead of time % 60000, to trigger the turn-off-leds section. You can see an example of this in the Blink Without Delay sketch.
Adding UL makes the constant Unsigned Long so the arithmetic is not demoted to 16-bit as is default in C. A frequent gotcha.
-br
Edit: sorry, posted too fast. Why not move the part that turns the lights on to setup(), and make a nice outer timer at 60000 ms that runs the inner lights-off timer.
|
|
|
|
|
51
|
Using Arduino / Programming Questions / Re: Program causes MCU to hang on boot
|
on: May 05, 2013, 07:42:43 pm
|
The first thing I would eliminate is an out-of-RAM condition. It's of particular interest because of all the strings you Serial.print(). A quick way to buy back a bunch of ram is to enclose the strings in your serial print statements in F(), like this: Serial.print("xyz"); // change this Serial.print(F("xyz")); // into this
Try that in all your Serial.print strings and see if it helps... -br
|
|
|
|
|
55
|
Using Arduino / Programming Questions / Re: long from byte - one substracted?
|
on: May 04, 2013, 06:20:41 pm
|
Love a little code golf. This problem can be worked without any arithmetic using a C union to allow two views of the same static memory: union { long thelong; byte thebytes[4]; } u;
void setup() { Serial.begin(57600); }
void loop() { u.thebytes[3] = 0x00; u.thebytes[2] = 0x69; u.thebytes[1] = 0xa8; u.thebytes[0] = 0xc4; Serial.print(u.thelong, HEX); delay(10000); }
Prints 69A8C4 -br
|
|
|
|
|