Pages: 1 [2]   Go Down
Author Topic: 30 Second Timer + LED Display + Pager Motor HELP!!  (Read 3080 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

We've set the TimerValue = 1000 that's 1 second.
If the delay on the motor function is 500 and each time it receives an execution command then
CurrentTime = PreviousTime + 500 am I Correct? Because of the delay.
Thus, if I had 4 consecutive beats, my TimerValue that should have decreased by 2x TimerValue--, will only be reduced once. Right?

You have no idea how much I appreciate your help!!!!

Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 207
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


« Last Edit: April 23, 2008, 10:27:31 am by BigMike » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 207
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's exactly the code I need to implement. Thanks BigMike. Seems like I'm sorted for now.

I can only hope that all of this works when we put it together. I'll keep you guys posted.

Thanks again!

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Should the second part of the code, the checking of the state of the motor, be in the main loop or should I modify my motor function?

Code:
void motor(int counter){

mtrCount = counter;

if (mtrState == mtrOn){
  digitalWrite(motPIN, HIGH);
  mtrCount --;

  if (mtrCount <= 0){
  // time's up, so stop
  mtrState == mtrOff;
  }
}
if (mtrState == mtrOff){
  digitalWrite(motPIN, LOW);
  mtrState = mtrStable;
}
...
 
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 207
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It should be in the main loop.  The motor() function is not needed anymore.


Mike
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have another problem.

I am trying to use Serial communication to receive data on the Arduino (Pin 0/Pin 1). The other prototyping board is a VX-Mega 128 and it is coded to send characters 'a' and 'b' over the air using a RF serial link that I bought from Sparkfun.

The receiver module is connected to my RX pin on the Arduino, despite baud rates being set the same, my arduino does not receive the characters. I even tried a wired method of communication but that didn't work either.

I tried Serial communication between two arduinos (MINI & Diecemilia) and that didn't work either.  I've looked at the software serial library, tried to run that too, but it's giving me funky errors.

We've got everything working for the most part, besides the communication. USB communication, like I said, works fine. Just the RF or wired communication between two MCU is a problem.


Logged

Pages: 1 [2]   Go Up
Jump to: