Show Posts
|
|
Pages: [1] 2 3 ... 14
|
|
2
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: debouncing an interrupt trigger
|
on: October 10, 2008, 08:28:48 am
|
|
I'm glad its all working.
However, I was actually thinking of doing that in the main loop, but as it is working, why not leave it there.
There is one problem - what happens when the value from millis() rolls over. I forget the numbers, but in older code the millis() function rolls over after about 9 hours. Currently the rollover occurs at about 50 days.
I think your button may stop working after the rollover. If your application won't be on for 50 days at a time this isn't a problem. If it will be then you may have a problem.
Regards,
Mike
|
|
|
|
|
3
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: debouncing an interrupt trigger
|
on: October 09, 2008, 04:39:54 am
|
|
You could use an external RC combination to remove the de-bounce before it gets to the interrupt pin.
What does the rest of your code look like? I ask because if it were me I'd use the millis() function to produce some code that operated every milli second and use a simple statemachine to handle the reading and de-bouncing of the switch.
Regards,
Mike
|
|
|
|
|
5
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading HELP
|
on: July 09, 2008, 08:06:53 am
|
Thanks for all replies! BigMike: I´ll try it. Thanks a lot in way how to thing about the problem! I think I will have to divide (not multiple) it by 2.11 to get the result on range 0-255. Isnt it true? You are correct, it should be a divide. Or you could calculate 256 / 540 and multiply by that. I haven't tried it on an arduino, but intuitively I guess is a floating point divide will take longer than a floating point multiply. It feels safer at least. Floating points... Is there some problem with them using as a value for a PWM output?
No problem - its just integer sums are quicker than floating point sums. Regards, Mike
|
|
|
|
|
6
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading HELP
|
on: July 08, 2008, 08:52:13 am
|
And also one important notes: the incoming useful data from the sensor are in range 160-700. Please do you know how to convert (lineary) these data to range 0-255? Thanks a lot! Sorry I don't have tome to look at your code problem, but I can help with this. The range 160 -> 700 is 540. You need this ranged to 256. 540 / 256 = 2.11 To do the ranging, first subtract 160 then multiply by 2.11 -> (x-160) * 2.11 That will put you into using floating point numbers (not necessarily a problem), but if you can stand 5% inaccuracy you could just multiply by 2 instead of 2.11 and stay in integer territory. Regards, Mike
|
|
|
|
|
7
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: How do i make a hallogenspot respond to arduin
|
on: April 14, 2008, 05:51:50 am
|
I have tried to build a cirquit with a the arduinooard on one side of a IRL540 mosfet, and the halogenspot and a transformator on the other side, i cant make it work. The halogenspot is a 12V 50W spot. Jo, You mention the transformer - is this an AC circuit? If is is an AC circuit, the interfacing requirments may be different. Can you sketch you circuit for us to see. Regards, Mike
|
|
|
|
|
14
|
Forum 2005-2010 (read only) / Interfacing / Re: 30 Second Timer + LED Display + Pager Motor HE
|
on: April 23, 2008, 10:13:14 am
|
While I was reading over my code, I read that I have used delayMicroseconds() in the motor function. Is there any way that I can use the millis() to prevent it from delaying the code? void motor(int pinNum) { digitalWrite(pinNum, HIGH); delayMicroseconds(5000); digitalWrite(pinNum, LOW); }
Shubs, As 5000 micro seconds is 5milliseconds, that can be implemented as a state machine. Define the states and set up two variables, one to hold the state and one to hold the time. #define mtrStable = 0 #define mtrOn = 1 #define mtrOff = 2 var byte mtrState; var byte mtrCount; mtrState = mtrStable; mtrCount = 0; Then in the loop, instead of calling the motor() function, change the motor state variable: if (someChar == 'a'){ mtrState = mtrOn; mtrCount = 500; }
then later check the motor state variable: if (mtrState == mtrOn){ digitalWrite(motPIN, HIGH); mtrCount = 500; mtrCount --;
if (mtrCount <= 0){ // time's up, so stop mtrState == mtrOff; } } if (mtrState == mtrOff){ digitalWrite(motPIN, LOW); mtrState = mtrStable; } ...
Something like that should work. Regards, Mike
|
|
|
|
|
15
|
Forum 2005-2010 (read only) / Interfacing / Re: 30 Second Timer + LED Display + Pager Motor HE
|
on: April 23, 2008, 04:29:20 am
|
Thanks for the replies BigMike & mem.
Mike, your code seems very easy and effective in terms of what I need to do. It was clear for the most part, although I had a couple of questions
a) what is the crtMillis value going to be when it loops through the first time? cause it seems like as soon as the value of crtMillis changes, you set it back to 0.
Lack of comments and poorly named variables makes it harder to understand  However, I can't see where I'm setting crtMilli back to zero. Each time through the loop I grab the current value of the millisecond counter using the line crtMilli = millis(); If it differs from the previous value (prvMilli) then at least one milli second has passed. Doing a test for different (!=) rather then just greater than means that you don't need to fix the millis() function timer rollover bug mem mentions. b) I didn't quite understand the TimerVal --; thing. Is it an int, I presume so. How does it know how much time has passed? Do I set it equal to another millis function?
TimerVal--; is a decrement by one instruction. Equivalent to TimerVal = TimerVal - 1;. There are pre- and post- decrement and increment instructions: i++; ++i; i-- and --i; So the timer works by counting down to zero in milliseconds. Regards, Mike
|
|
|
|
|