Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   toggle switch (http://www.chiefdelphi.com/forums/showthread.php?t=41983)

half geek 27-01-2006 21:23

Re: toggle switch
 
Quote:

Originally Posted by Windward
So, what would that code look like?

Code:

char fire(void) //Will return 0 until firing is complete
{
  static unsigned int counter = 0;
  printf("Piston Forwardr");
  relay1_rev = 0;
  relay1_fwd = 1;
  if (counter > MAX_COUNTER) //MAX_COUNTER is defined in .h
    {
      printf("Piston Backr");
      relay1_fwd = 0;
      relay1_rev = 1;
      printf("Firing done!r");
      counter = 0;
      return 1;
    }
  else
    {
      counter++;
      return 0;
    }
}

This will push the piston forward for MAX_COUNTER processor loops (26.2ms each), then retract the piston. When it is called, it should continue being called until it returns a 1.
I'm not exactly sure what the original code is trying to do, but this is my best guess.
Also, its probably error-licious for lack of testing and sorta slapping it together.
I hope it helps though.

N7UJJ 27-01-2006 22:38

Re: toggle switch
 
Quote:

Originally Posted by KenWittlief

remember the spike has three output states: forward, reverse, and off.

Actually four:

forward reverse
off off
off on
on off
on on

Although the spike is labeled fwd and rev, it is really two sperate on/off relays. Doesn't make a lot of sense when hooked up to a piston to have both on, but there are other applications...


All times are GMT -5. The time now is 21:42.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi