Hi guys!
I’m brand new to RC builds, in fact this long board build will be my first ever! Please excuse me if I say something wrong or doesn’t make sense!
Currently I am trying to control my setup via a Nunchuck. I’ve seen some tutorials out there about how to calibrate the ESC via an arduino, and I have been successful in doing so. However, is there anyway I can customize the controls?
Ideally I would like a setup where the “Z” button is trigger so the motor will only run if the user holds down the “Z” button.
The code I attached only allows control of the motor speed when “Z” is pressed, however, if a user pushes the throttle to a certain point and lets go of “Z” the motor will cruise at that speed. The motor will not stop until the user pushes “Z” AND the throttle is in the neutral position on the nunchuck.
Looking at the code it makes sense why this happens, but the problem arises when I add the code that is commented out. I figured this would work (which it kinda does) in terms of making the nunchuck function how i want it to, but there seems to be some sort of delay. Basically I have to tap the “Z” button multiple times in order for me to re-accelerate the motor again.
I hope that makes sense, if not I can try to clarify.
#include <Servo.h>
#include <Wire.h>
#include "nunchuk.h"
Servo esc;
int motor;
void setup() {
// put your setup code here, to run once:
esc.attach(9);
esc.writeMicroseconds(1000);
Serial.begin(9600);
nunchuck_setpowerpins();
nunchuck_init();
Serial.print("Ready\n");
}
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
if(Button_Z == 1) //Only if the "Z" button is pressesd excute the following code
{
Serial.print("Pressed\t");
motor = map(joystick_Y, 122,213,1000,2000); //map the joystick postion to motor speed
esc.writeMicroseconds(motor); //output information to the motor
Serial.print("sensor = "); //report information to serial monitor
Serial.print(joystick_Y);
Serial.print("\t output = ");
Serial.println(motor);
}
//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.write(0); //send 0 to the motor
// Serial.print("sensor = ");
// Serial.print(joystick_Y);
// Serial.print("\t output = ");
// Serial.println(motor);
//}
delay(1);
}
Could anyone guide me with this? or is there a better way to do this sort of thing?
Any help is appreciated!!
ESC: https://hobbyking.com/en_us/hobbykingr-tm-x-car-beast-series-esc-1-8-scale-120a.html
Best, -H