Show Posts
Pages: [1] 2 3 ... 14
1  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Spam fighting request on: September 09, 2008, 05:50:47 am
I also find the spam objectionable.

There are technical solutions and volunteers - why not use them?

Mike
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
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Questions about millis() on: March 17, 2008, 09:30:28 am
Quote

From that link:
Quote
You want to blink an LED only on Christmas during leap years? Totally possible now.

Made me chuckle smiley

Mike
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Fading HELP on: July 09, 2008, 08:06:53 am
Quote
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.

Quote
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
Quote
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
Quote
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
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Analog input to control LED ladder on: April 14, 2008, 05:45:55 am
Can you show us your code?

9  Forum 2005-2010 (read only) / Interfacing / Re: max with a rotary encoder on: April 02, 2008, 11:26:50 am
Do you need some "debounce" type coding in there?  You may be having trouble at the transistions.

Mike
10  Forum 2005-2010 (read only) / Interfacing / Re: Connecting Arduino to VGA on: July 22, 2008, 10:01:22 am
It should be possible - it seems to use rs232 type serial at TTL levels which the AVR chip can do, ither with the UAT, or one of the soft-serial libraries.

According to the website, it isn't available yet, though.

Mike
11  Forum 2005-2010 (read only) / Interfacing / Re: Syncronized Serial communication with Arduino on: May 07, 2008, 05:19:47 am
One way this is done is to frame the data. This is often done use DLE STX bytes to signal the start of transmission and DLE ETX to signal the end. Within the data, a value pair of DLE STX or DLE ETX  gets escaped (preceded) with another DLE, which is then stripped out at the receiving end.

STX has a value of 0x02, ETX a value of 0x03 and DLE is 0x10.

The following is the best description I could find online:

http://www.cc.gatech.edu/classes/AY2005/cs4251_fall/class14.ppt#669,2,Character-Oriented Framing



Mike
12  Forum 2005-2010 (read only) / Interfacing / Re: 30 Second Timer + LED Display + Pager Motor HE on: April 23, 2008, 10:42:08 am
It should be in the main loop.  The motor() function is not needed anymore.


Mike
13  Forum 2005-2010 (read only) / Interfacing / Re: 30 Second Timer + LED Display + Pager Motor HE on: April 23, 2008, 10:17:30 am
Quote
Sorry if I've confused you, but the pager motor vibration length is supposed to be half a second so it's 500 milliseconds. I could make the timing slightly smaller but I want refrain from that.

Ah - so in my previous post, change the mtrCount variable to an int and set it to 500 in the loop.

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
Quote
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?

Quote
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:

Code:
if (someChar == 'a'){
  mtrState = mtrOn;
  mtrCount = 500;
}

then later check the motor state variable:
Code:
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
Quote
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 smiley

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.

Quote
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



Pages: [1] 2 3 ... 14