Author Topic: Need Help  (Read 3752 times)

0 Members and 1 Guest are viewing this topic.

Offline sbarneyTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Need Help
« 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?

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Need Help
« Reply #1 on: August 04, 2008, 04:51:14 PM »
keyboard buttons? or a 4x4 keypad matrix?  ??? uart?  ???

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Need Help
« Reply #2 on: August 04, 2008, 04:56:19 PM »
please provide more details
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline Rand alThor

  • Full Member
  • ***
  • Posts: 83
  • Helpful? 0
  • Lord Tristan the Dragon Slayer
Re: Need Help
« Reply #3 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

paulstreats

  • Guest
Re: Need Help
« Reply #4 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)

Offline sbarneyTopic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: Need Help
« Reply #5 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.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,704
  • Helpful? 173
    • Society of Robots
Re: Need Help
« Reply #6 on: August 09, 2008, 08:18:03 AM »

 

SMF spam blocked by CleanTalk