Interfacing Between Arduino and ESC via a Wii Nunchuck

Hi Guys,

I am relatively new to creating projects with arduino embedded in them, in fact this is my first one!
Please excuse me if i say something off, or incorrect!

Currently I am trying to use a wii nunchuck to control an electric longboard. Ideally I would like it so that the “Z” button acts like a trigger. (So the motor will only run if the user is pressing the “Z” button).

The issue I am facing is that in my code (attached) there is a 4 seconds delay when attempting to re-accelerate. Basically, say a user presses the “Z” button and begins to adjust the throttle to the desired speed, but then say they decide to release the “Z” button to slow down. If they wish to re-accelerate now (by re-pressing the “Z” button and adjusting the throttle) they must hold “Z” for atleast 4 seconds with the throttle in the neutral position otherwise nothing will happen.

I hope that makes sense, otherwise I can try to clarify!

I thought my code would make it instantaneous so there would be no delay. Would anyone know why this problem is occurring and how I can fix it?

Any help is appreciated!!!




#include <Servo.h>
#include <Wire.h>
#include "nunchuk.h"

Servo esc;
int motor;

void setup() {
  // put your setup code here, to run once:


void loop() {
  // put your main code here, to run repeatedly:

  nunchuck_get_data();                                        //Get data from nunchcuk.

  int joystick_Y = nunchuck_joyy();                           //Variable to store joystick vertical information
  int Button_Z = nunchuck_zbutton();                          //Variable to store "Z" button information
  int Button_C = nunchuck_cbutton();                          //Variable to store "C" button information

    motor = map(joystick_Y, 122,213,1000,2000);               //map the joystick postion to motor speed

if(Button_Z == 1)                                             //Only if the "Z" button is pressesd excute the following code
    esc.writeMicroseconds(motor);                             //output information to the motor
    Serial.print("sensor = ");                                //report information to serial monitor
    Serial.print("\t output = ");
else if (Button_Z == 0)                                   //If the "Z" button IS NOT pressed excute this code
  Serial.print("NOT Pressed\t");
   // motor = map(joystick_Y, 122,213,1000,2000);
    esc.writeMicroseconds(0);                                        //send 0 to the motor
    Serial.print("sensor = ");
    Serial.print("\t output = ");