Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/03/03 06:25
Read: times


 
#47331 - RE: same old waqar
Responding to: ???'s previous message
Hi Waqar,

I applaud you for your persistance.

You explanation of how you did your pulse detection was completely baffling, and I can't imagine that you got it working. But your algorithm description later in this thread was pretty straight forward. It should be simple to implement.

OK. You say you've done your research and read all the replies, but just need a little example. Your persistance, but not your effort, is paying off.

Here is a simple state machine to keep track of various states and inputs while unlocking a combination lock. There's a lot left undefined here, but it should be obvious what I'm trying to do, even if I've mistyped.

void combination_lock (void)
{
static char state = LOCKED;

switch (state)
{
case LOCKED:
if (turn_direction == RIGHT)
state = GET_FIRST_NUMBER;
break;

case GET_FIRST_NUMBER:
if (number == FIRST_NUMBER)
state = TURN_AROUND_1;
else if (turn_direction == LEFT)
state = LOCKED;
break;

case TURN_AROUND_1:
if (turn_direction == LEFT)
state = GET_SECOND_NUMBER;
else
state = LOCKED;
break;

case GET_SECOND_NUMBER:
if (number == SECOND_NUMBER)
state = TURN_AROUND_2;
else if (turn_direction == RIGHT)
state = LOCKED;
break;

case TURN_AROUND_2:
if (turn_direction = RIGHT)
state = GET_THIRD_NUMBER;
else
state = LOCKED;
break;

case GET_THIRD_NUMBER:
if (number == THIRD_NUMBER)
state = UNLOCKED;
else if (turn_direction == LEFT)
state = LOCKED;
break;

case UNLOCKED:
if (turn_direction == RIGHT ||
turn_direction == LEFT)
{
state = LOCKED;
lock_status = CLOSED;
}
else
lock_status = OPEN;
break;

default:
state = LOCKED;
lock_status = CLOSED;
}
}

Don't ask me to translate C to assembler...I use a compiler to do that, you can do it as you choose. Likewise, it's your task to understand the concept enough to apply it to your project.

Dennis

List of 26 messages in thread
TopicAuthorDate
removing from check list            01/01/70 00:00      
   RE: removing from check list            01/01/70 00:00      
      RE: removing from check list            01/01/70 00:00      
      RE: removing from check list            01/01/70 00:00      
      RE: removing from check list            01/01/70 00:00      
         RE: removing from check list            01/01/70 00:00      
   RE: removing from check list            01/01/70 00:00      
   RE: removing from check list            01/01/70 00:00      
      RE: removing from check list            01/01/70 00:00      
         RE: removing from check list            01/01/70 00:00      
            mahmood Elnasser            01/01/70 00:00      
         RE: removing from check list            01/01/70 00:00      
   same old war            01/01/70 00:00      
      RE: same old waqar            01/01/70 00:00      
      RE: same old war            01/01/70 00:00      
         Tutorials addition            01/01/70 00:00      
         RE: same old war            01/01/70 00:00      
            RE: same old war            01/01/70 00:00      
         RE: same old war            01/01/70 00:00      
         Stepper Motor Control            01/01/70 00:00      
            RE: Stepper Motor Control            01/01/70 00:00      
               RE: Stepper Motor Control            01/01/70 00:00      
                  RE: Stepper Motor Control            01/01/70 00:00      
   i will make the circuit            01/01/70 00:00      
      Congratulations - Mike            01/01/70 00:00      
         RE: Congratulations - Mike            01/01/70 00:00      

Back to Subject List