Hi guys!
I'm pretty new to Arduino but really excited by the possibilities! I'm currently working on a sketch to control a brushless motor with an Xbox 360 controller.
When trying to use the button presses from the controller, this seems to be the format I've seen from the couple of examples I've found:
XboxRCV.getButtonPress(L2,0)
and
Xbox.getButtonPress(L2, i)
In those snippets, what do the ,0 and ,i do? I would have thought the code would just be Xbox.getButtonPress(L2)
Cheers,
My sketch so far:
#include <XBOXRECV.h>
#include <Usb.h>
#include <Servo.h>
USB Usb;
XBOXRECV XboxRCV(&Usb);
Servo motor1;
int motor_power = 0; // working value to control the power of the motor
int motor_output = 0; //value from 0-179 which is sent to ESC
int const motor_output_pin = 9; // pin which the ESC is connected to
int const range = 10000;
void setup(){
Serial.begin(9600);
if(Usb.Init() == -1) { //USB.Init will return -1 for shield disconnected, and 0 if connected
while(1); //halt until shield is connected
}
motor1.attach(motor_output_pin);
}
void loop(){
Usb.Task();
motor_power = motor_power + XboxRCV.getButtonPress(R2);
if(motor_power > range)
motor_power = range;
motor_power = motor_power - XboxRCV.getButtonPress(L2);
if(motor_power < 0)
motor_power = 0;
motor_output = map(motor_power, 0, range, 0, 179);
motor1.write(motor_output);
delay(1);
}
I'm not able to test it out yet as still waiting on my USB Host Shield, but if anyone can spot any major errors I'd appreciate it!