CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

is there a better way to do this
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pdl



Joined: 01 Jun 2005
Posts: 45
Location: UK

View user's profile Send private message

PostPosted: Wed May 03, 2006 9:35 am     Reply with quote

Hi Humberto

The Normal state of the switch is low while not pressed when pressed it goes HIGH

Pete
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Wed May 03, 2006 10:30 am     Reply with quote

Why not try something like this:

Code:

int8 x, y, axis;
short led_bank_select;

void change_led_bank (short bank) {
   if (bank) {
      // this is the lower bank
      axis = input_a() &0xf;
      output_b(axis);
   } else {
      // this is the upper bank
      axis = input_a() &0xf;
      output_b(axis << 4);
   }
}


void main () {
   // set this to your default
   led_bank_select = TRUE;
   y=0;

   while (1){
      if (input(PIN_A4)) {
         // simple debounce to make sure the button was pressed.
         for (x=0;x<40;x++){
            if (input(PIN_A4))
               y++;
            // if we hit 20 it is more then likely a valid button press
            if (y >= 20) {
               led_bank_select = !led_bank_select;
               change_led_bank (led_bank_select);
               break;
            } // end if
            delay_ms(5); // delay for a small amount of time between each reading
         } // end for
         // reset y to 0
         y = 0;
      } // end if
   } // end while
} // end main



If anything, maybe it will give you a few ideas.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group