View Single Post
  #5   Spotlight this post!  
Unread 17-01-2005, 21:27
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: Rookie programmer in need of help.

I think you are saying that after the switch is hit, then a new section of code is enabled. Yes? And I think you want the code to remember that the switch had been hit, even after the switch is no longer pressed?

(experienced programmers, please check for errors. I did this off the top of my head!)

In the file user_routines.c...


In the function User_Initialization(), make sure:

Code:
// tell the controller that we want to use io pin 15 as an input:
//
digital_io_15 = INPUT;  // or whichever input you want to use

also, somewhere in user_routines.c, near the top:
Code:
#define  MY_SWITCH rc_dig_in15  // makes the other code easier to read
In the function Default_Routine(void), add your code like this:

near the top
Code:
static unsigned char switchWasHit = 0;
later:
Code:
// when the switch is hit, it closes, and pulls the input low i.e. 0
//
if ( MY_SWITCH == 0 )  
   switchWasHit = 1;   // remember forever

if ( switchWasHit )
{
  /* this is never executed before the switch is hit, and is
      always executed after the switch is hit
  */
}
Remember that Default_Routine(void) is executed over and over again, about 39 times a second.

Does that help?
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.