935Views12Replies

Author Options:

Does anyone know a way to do a debounce (sketch) without a delay? Answered

I've been trying to mod an xbox 360 controller with an arduino. Unfortunately the switch I have bounces allot and has really been screwing with my sketch. Long story short I've tried allot of different debounces but as soon as i put a delay (); in anywhere in the sketch the controller just shuts down. I don't know why but i think the people who make the game may have some ant-hacking built into the game. Any help is appreciated. Thanks in advance.   

12 Replies

user
steveastroukBest Answer (author)2012-04-16

Funnily enough, I'm working on a boucing issue in code for my work right now, and I shall be fixing it today with my usual routines.

I suspect that the xbox is constantly handshaking with the controller, and expects a message back every few milliseconds- what's in your message doesn't have to be changed every time- so you can still contain bounce code.

Select as Best AnswerUndo Best Answer

user

I'm not quite sure what your saying. I'm using an if statement triggered by the button being high, then righting high then low quickly. if (button =HIGH) { DigitalWrite (shoot,HIGH);
DigitalWrite (shoot,LOW);
}
I've tried to put a delay above, below and in the if statement all disable the trigger's actions. I'm not sure what "my message" is. Thanks for you're help, sorry I'm a bit of a noob.

Select as Best AnswerUndo Best Answer

user

Where's your deboucing ? a delay isn't a debounce.

Do you mean digitalwrite never changes state ? How do you know ?

Steve

Select as Best AnswerUndo Best Answer

user

I mean debounce when I said delay. I said delay because the delay is the part causing problems.  The digitalWrite works because the rapid fire is working it's just that it stops 5-6 seconds after the button is released. The handshake thing is correct the max delay I can put in is delayMicroseconds (10). Thanks for your help, I think I should just find a better switch and live with it. 

Select as Best AnswerUndo Best Answer

user

Post your whole code. I can't work on a snippet of a snippet. Let me see what you are trying to do. Make sure the code is commented. The secret is to have a task watching the keys, and a separate task sending the handshake.

Select as Best AnswerUndo Best Answer

user

Sorry I thought about posting it in the last comment but thought it would be to long for a comment (no 140 character limit here). First off I am in no way a programmer and just started like two weeks ago.
int val = 0; // stores values of the digitalread of the button
int button = 4; // positive leg of buttton connected fromm 3.3v to pin 4
int shoot = 2; // positive wire comming form the trigger/button on xbox controller

void setup() { // setting pinmode and starting serial connection
Serial.begin (9600);
pinMode ( button, INPUT);
pinMode (shoot,OUTPUT);
}
void loop() {
val = digitalRead (button); // reading button storing value
Serial.println (val); // just checking make sure button works
if (val == HIGH) { // if button is pressed
digitalWrite (shoot,HIGH); // needs to go high then low inorder
digitalWrite (shoot,LOW);// to fool conntroller
}
val = LOW; // resting val
}

Thanks for all your help

Select as Best AnswerUndo Best Answer

user

UPDATE: also tried a analogread but it was to slow. Also sped it up and it was still to slow for the Xbox LINK. Don't know if that helps but tried it too. Thanks for you're help. 

Select as Best AnswerUndo Best Answer

user

You probably need to have a separate process that deals with the messaging, whilst your keyscan is in the main loop.

Steve

Select as Best AnswerUndo Best Answer

user

Thanks got it working allot better. Publish the instructable soon. Thanks for your help.

Select as Best AnswerUndo Best Answer

user

https://www.instructables.com/id/Mod-Xbox-360-Controller-Using-Arduino-MW3/
the Instructable.

Select as Best AnswerUndo Best Answer

user
iceng (author)2012-04-16

Use mercury whetted switches they don't bounce.

or this very simple logic.  .  .  .   A

Select as Best AnswerUndo Best Answer

user
Zaphod Beetlebrox (author)iceng2012-04-16

Thanks, but the project is already vary bulky i'm not sure i want to add another circuit to it and breadboard. I was thinking if there was any way to do this more in the programming sense. Maybe i'll just try some other types of switches. Thanks for the speedy response.

Select as Best AnswerUndo Best Answer