Show Posts
Pages: [1] 2 3 ... 49
1  Using Arduino / Project Guidance / Humans are slow, how not to block on: July 20, 2014, 02:22:01 pm
Just like the title says, my problem is that humans are slow and interacting with them blocks the rest of my program.  This problem doesn't really have to do with any one particular project, but is something that seems to come up for me all the time.  

Let's say I'm have a program like this.  I have a function that runs a really tight loop and does some really important stuff called importantFunction().  We can't allow that function to be blocked for more than a few milliseconds.    

Now I want a function that allows the user to set the time.  It has to ask sequentially for the month, day, year, hour, and minute and it can't block the importantFunction.  So I'll make this function quick and make a pointer to this function and call it over and over again.  One obvious solution is to have all of those answers as global variables and set them to -1 or something so I know where I am in the chain and each time through see where I am and check real quick if the user has entered anything yet.   For just setting the time that sounds cool, but once my program has a lot of different things it can do, keeping up with all those globals becomes an issue.  

But I don't see another option.  If I wrote a blocking function I'd have month, day, year, hour, and minute as local to the function.  They'd be in RAM on the stack but only while the function is alive.  Then they're gone leaving space for the next thing that has to ask three or four questions in a row.  But if I don't want to block I have to leave a whole bunch of globals around or use static variables and that's going to have the same memory issue.  I also have to have a way to get this information back to the part of the program that was asking.  I know how to use a callback, but again I have to leave all this information in a global place so it can be used by another function.  

How is this supposed to work?
2  Using Arduino / Project Guidance / Multiple switches at once / water level meter on: July 20, 2014, 01:53:26 pm
Hi guys,

I want to build a gauge for the water level in a tank.  I have a float with a magnet in it and a long tube that the float fits around and a bunch of hall effect sensors.  The idea is to put one HE sensor at each 1 gallon increments up the long tube and as the flost goes up or down it will turn them on or off. 

My question comes to how to best read them all.  It seems a waste to bring them all in to individual pins and read them one by one.  It seems like some sort of resistor ladder and I can do it with one analog pin.  I know how that works when only one switch at a time will be closed, but how do I work that out here where all of the switches up to a point will be closed. 

I hope that makes enough sense that someone can help.

Thanks in advance
3  Using Arduino / Programming Questions / endianess and 32 bit data on: July 02, 2014, 09:03:22 am
I wonder if someone cal help clear up my thinking here.  I'm dealing with some data that is making a change from 16 bit to 32 bit.  The 16 bit data was little endian, so if we call the low order byte 1 and the high order byte 2 the order was 1,2. 

When this gets extended to 32 bit, does the order now go 1,2,3,4 or does it go 3,4,1,2?  I guess my question is, I understand the byte order for the 16 bit chunks, but does that extend to 32 bit or does that only apply to the 16 bit chunks?  Or is that another thing that can go both ways and I have to figure out what this one particular program does?
4  Using Arduino / Programming Questions / Re: how do i use millis(); as a while loop on: July 01, 2014, 09:01:20 pm
I don't see millis involved anywhere in that code.

This is the only while loop I see.


I wouldn't expect that to ever exit.  If FrontRight_Mid_sensorvalue is 1 when you enter the loop and nothing in the while loop ever changes it and that Forward function doesn't change it then it will always just stay as a 1.  So it will always be true and you'll never leave that loop.  Maybe somewhere in that loop you should check the sensor or whatever it is.
5  Using Arduino / General Electronics / Re: Turn the LED on when the switch is open on: June 27, 2014, 11:20:39 pm
It works when I try it out on a breadboard, but that is true of a lot of bad ideas. 

6  Using Arduino / General Electronics / Turn the LED on when the switch is open on: June 27, 2014, 11:19:07 pm
Is this an OK thing to do?  If not why?  Is there something I should change?

I want it so that when the switch is closed the light will be off, but when the switch is open the light will go on.  It will be monitoring a door and I have to use the switch that is already there.  The switch is closed when the door is closed and open when the door is open. 

7  Using Arduino / Programming Questions / Re: can I call a function to replace a for statement? on: June 19, 2014, 05:07:11 pm
No there is not a way to call a function and have it do that.  You just want to replace the text, a function would replace the whole block of code. 

You could write a function that does the whole thing including the two calls to output() in the for loop.  If you need information for that to work then pass it to said function you create.

If you just want to replace text there's always the preprocessor macros and defines but that would be a very slippery and dangerous slope in this case. 

If you just want to save the typing, select the for loop and press control+c on your keyboard.  That will copy it to the clipboard.  Then anytime you want to type it you just press control+v and it will insert that text right in there with one keystroke. 
8  Using Arduino / Programming Questions / Re: Why does this not work?? on: June 19, 2014, 05:01:44 pm
It looks like it should fade one led up and the other down and then reverse that.  Wait ten seconds doing nothing, the led on pin 5 will stay lit during the 10 second wait time. 

After the ten seconds of nothing is done, it looks like func2() will fade them both up and back down again together.  Then another 10 seconds of nothing happening only this time both leds will be off during the wait. 

Does that sound anything like what you see?  If not then we need to talk about how you have it hooked up.
9  Using Arduino / Programming Questions / Re: Sending ASCII value to function on: June 17, 2014, 05:06:10 pm
Or in other words 'A' is just another way to write 65.  Just like you could also write it as 0x41.  They all represent the exact same thing.

Computers don't do letters.  Only numbers.  That's why ASCII was created in the first place.
10  Using Arduino / Programming Questions / Re: Pattern based if statements? on: June 17, 2014, 05:02:43 pm
He's both creating a new variable and assigning to it and testing for 0 at the same time.  If spaceTimer(0) returns 0 then 0 gets assigned and the if doesn't run.  If spaceTimer(0) returns anything non-zero then the assignment will be of that value and evaluate as true sending you into the conditional block. 
11  Using Arduino / Programming Questions / Re: will someone look at this sketch and tell me where i messed up on: June 17, 2014, 04:58:51 pm
Not to steal Paul S. 's thunder but...

Your code is supposed to do something.  It would really help if you shared what that something was.

Your code is obviously doing something else, or you wouldn't be posting it here.  It would really help if you shared that as well. 

Nobody here is going to go through all of that code and try to figure out what you want it to do and try to find the mistake hidden in it.  Tell us what is going wrong and someone can probably help you track down the relevant bit of code.
12  Using Arduino / Programming Questions / Re: Serial.println(8000*100); return 14464 ???? on: June 17, 2014, 11:52:10 am
You're using int math.  THe largest value an int can hold is 65535.  If you try to stuff 80000 in there you get 80000 - 65536 = 14464.

Use longs instead of ints as the last post suggested and your problem will be solved.
13  Using Arduino / Programming Questions / Re: How to convert tree Int to one Int? on: June 16, 2014, 02:30:03 pm
smiley  Fair enough.
14  Using Arduino / Programming Questions / Re: Arithmetic Question on: June 16, 2014, 02:27:34 pm
Integer math.  you have to learn to think like a computer.  

391 / 880 == 0
1 / 880 == 0

So you have pVolt0 * 0 + 0 and that will be 0 all day long.

1 / 880.0 = 0.0011363636...

Make the 880 a float (by writing 880.0) and it will evaluate as a float.  
15  Using Arduino / Programming Questions / Re: How to convert tree Int to one Int? on: June 16, 2014, 12:31:03 pm
long int abc = b * 100 * 100 + a * 100 + c;

You better promote somebody on the right side to Long or you're going to have an overflow. 
Pages: [1] 2 3 ... 49