Society of Robots - Robot Forum

Software => Software => Topic started by: sbarney on August 04, 2008, 03:35:16 PM

Title: Need Help
Post by: sbarney on August 04, 2008, 03:35:16 PM
I'm trying to write a function in C to detected 3 button presses within 3 seconds.  I'm using a PIC16F883 with the CCS compiler.  Can anyone help?
Title: Re: Need Help
Post by: pomprocker on August 04, 2008, 04:51:14 PM
keyboard buttons? or a 4x4 keypad matrix?  ??? uart?  ???
Title: Re: Need Help
Post by: airman00 on August 04, 2008, 04:56:19 PM
please provide more details
Title: Re: Need Help
Post by: Rand alThor on August 04, 2008, 07:07:51 PM
I'm not sure I understand what you need, exactly(please elaborate), but if you mean that you need a C function to detect if any three buttons are pressed within three seconds of each other, it should look something like this:

Code: [Select]
bool HaveThreeButtonsBeenPressedWithinThreeSecondsOfEachOther( void )
{        //Start function.
int accumulator = 0; //0 seconds have passed so far.
int numOfButtons = 0; //The number of buttons pressed.
while(accumulator <= 3)
{
while(/*Onesecondhaspassed ==*/true)
{
if(onebuttonofthetypeispressed)
{
numOfButtons++;//Increment the number of buttons pressed.
}
accumulator++;//Show that one second has passed.
}
}
if(numOfButtons == 3)
{
return true;
}
else
{
return false;
}
}



Of course, I wouldn't trust this code, as I haven't programmed in C/C++ for quite a while, having shown much more intrest in C# (in my opinion, the best programming language, for now, at least). And I got kinda lost in the middle( ???), as I have never had to program in a text editor like this ever (Always used syntax highlighting and auto-indentation, etc.).

But this should be the general idea, presuming you need what I assummed you needed. OK, I'm just confusing you now. I'll be quiet now.  :-X
Title: Re: Need Help
Post by: paulstreats on August 04, 2008, 07:11:24 PM
The programming part is relatively straight forward. Its the rest of the setup that needs to be right before you can program it tho... (e.g. do you have a deboincing circuit on the button? if not then a single push on it would register as multiple pushes on the mcu)
Title: Re: Need Help
Post by: sbarney on August 05, 2008, 08:51:20 AM
Sorry for not being more specific.  I am trying to enter test mode for a new product.  I'm doing this in order to verify the distance between a hall effect sensor and a magnet.  One activation of a keyswitch will send me into a bypass mode.  If the same keyswitch(input) is activated another 2 times within 3 seconds, I enter the test mode.  Again sorry.  This is my first code writing project with a PIC.
Title: Re: Need Help
Post by: Admin on August 09, 2008, 08:18:03 AM
Google (http://www.google.com/search?hl=en&safe=off&rls=DGUS%2CDGUS%3A2006-11%2CDGUS%3Aen&q=push+button+source+code+PIC+.c)