Jump to content

Slowing down commands

hazza_ob

So I'm back with another problem, this time to do with an addition feature of a program which interfaces a wii nunchuck with the two servos in a 'pan and tilt' camera mount.

 

The code: 

void loop(){  nunchuk.update();if ( nunchuk.cButton == 1 ) {    // light the LED if 'c' button is pressed    mode = mode + 1;    digitalWrite(ledPin8, HIGH);  }  else {    digitalWrite(ledPin8, LOW);  }if (mode >= 3) {    mode = 0;  }}

so here what I'm trying to do is have 3 modes set on 0,1 and 2. The mode is changed by adding 1 to the variable 'mode' however to eliminate delay in the refresh of the nunchuck i've tried to keep a delay as short as possible. However when button c is 1 (pressed down), the mode will continuously keep changing as 1 is always being added to 'mode'. So my question is this: is there anyway to make the program to add just 1 when the button c is pressed almost like a memory cell but won't continually add 1 like it is doing now? i've tried "delay(<time>);" already and it doesn't work. as always an example is always helpful and if i haven't made sense please tell me haha.

Thanks -Harry

Link to comment
Share on other sites

Link to post
Share on other sites

Couldn't you add a "nunchuk.cButton == 0" after you're done using it to get inside the if statement? Or make a boolean that is is flipped in accordance to nunchuk.cButton and put that as the condition for the if statement?

I own and use, sorted from newest to oldest: SteelSeries 6Gv2. Microsoft SideWinder X4. Mionix Naos 7000. Zowie EC1 Evo. Microsoft SideWinder X8. Microsoft IntelliMouse Explorer 3.0. Dell U2414H. Samsung P2270H. AKG K273 Pro. Sennheiser HD555. Razer Goliathus Speed Medium. Func 1030 L. Qpad CT Medium.

I used to own: Razer DeathAdder 3G. Razer Krait. IntelliMouse Optical 1.1. SteelSeries QcK.

Link to comment
Share on other sites

Link to post
Share on other sites

i have a plan: to initialise the mode change when button 'c' is released... updates to follow

Link to comment
Share on other sites

Link to post
Share on other sites

Couldn't you add a "nunchuk.cButton == 0" after you're done using it to get inside the if statement?

the problem I'm having is that its repeating the command many times per second so button 'c' is being registered many times every second each time the loop recycles making the 'mode' variable increase way too fast. i need a way of slowing this down so it goes up by one. nunchuk.cButton automatically goes back to 0 once i let go - this isn't the problem

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×