hi, im making a unojoy with a usb host shield thats connected to a wireless xbox 360 reciever usb, im basically it for a ps3 that would be controlled by a 360 controler
UnoJoyArduinoSample_ino:27: error: expected constructor, destructor, or type conversion before '.' token
UnoJoyArduinoSample_ino:28: error: expected unqualified-id before 'if'
UKHeliBob:
Check where your loop() function starts and ends.
This code
Usb.Task();
if(Xbox.XboxReceiverConnected)
{
for (uint8_t i = 0; i < 4; i++) {
if (Xbox.Xbox360Connected[i]) ] }
}
is not in a function.
//Import required libraries
#include <XBOXRECV.h>
#include "UnoJoy.h"
//Instantiate Global Variables
//USB host shield
USB Usb;
//Xbox conroller library
XBOXRECV Xbox(&Usb);
int val;
void setup(){
setupUnoJoy();
}
void loop(){
// Always be getting fresh data
dataForController_t controllerData = getControllerData();
setControllerData(controllerData);
Usb.Task();
if(Xbox.XboxReceiverConnected){
for (uint8_t i = 0; i < 4; i++){
if (Xbox.Xbox360Connected[i]){
//Add code here to do handle connected controler
}
}
}
}
dataForController_t getControllerData(void){
// Set up a place for our controller data
// Use the getBlankDataForController() function, since
// just declaring a fresh dataForController_t tends
// to get you one filled with junk from other, random
// values that were in those memory locations before
dataForController_t controllerData = getBlankDataForController();
// Since our buttons are all held high and
// pulled low when pressed, we use the "!"
// operator to invert the readings from the pins
controllerData.triangleOn = !Xbox.getButtonPress(i,Y);
controllerData.circleOn = !Xbox.getButtonPress(i,B);
controllerData.squareOn = !Xbox.getButtonPress(i,X);
controllerData.crossOn = !Xbox.getButtonPress(i,A);
controllerData.dpadUpOn = !Xbox.getButtonPress(i,UP);
controllerData.dpadDownOn = !Xbox.getButtonPress(i,DOWN);
controllerData.dpadLeftOn = !Xbox.getButtonPress(i,LEFT);
controllerData.dpadRightOn = !Xbox.getButtonPress(i,RIGHT);
controllerData.startOn = !Xbox.getButtonPress(i,START);
controllerData.selectOn = !Xbox.getButtonPress(i,BACK);
controllerData.homeOn = !Xbox.getButtonPress(i,XBOX);
// And return the data!
return controllerData;
}
hi thanks for the reply, the above is the edited code now im just getting one error:
UnoJoyArduinoSample_ino.ino: In function 'dataForController_t getControllerData()':
UnoJoyArduinoSample_ino:49: error: 'i' was not declared in this scope
The error message is telling you exactly what is wrong.
On that line, and many others in the getControllerData() function the variable i is used as a parameter for the getButtonPress() function. Where is the variable i declared and where is it given a value ?
//Import required libraries
#include <XBOXRECV.h>
#include "UnoJoy.h"
//Instantiate Global Variables
//USB host shield
USB Usb;
//Xbox conroller library
XBOXRECV Xbox(&Usb);
int val;
void setup(){
setupUnoJoy();
Serial.begin(115200);
if (Usb.Init() == -1)
Serial.print(F("\r\nOSC did not start"));
}
void loop(){
// Always be getting fresh data
dataForController_t controllerData = getControllerData();
setControllerData(controllerData);
Usb.Task();
if(Xbox.XboxReceiverConnected){
for (uint8_t i = 0; i < 4; i++){
if (Xbox.Xbox360Connected[i]){
//Add code here to do handle connected controler
}
}
}
}
dataForController_t getControllerData(void){
// Set up a place for our controller data
// Use the getBlankDataForController() function, since
// just declaring a fresh dataForController_t tends
// to get you one filled with junk from other, random
// values that were in those memory locations before
dataForController_t controllerData = getBlankDataForController();
// Since our buttons are all held high and
// pulled low when pressed, we use the "!"
// operator to invert the readings from the pins
controllerData.triangleOn = !Xbox.getButtonPress(i,Y);
controllerData.circleOn = !Xbox.getButtonPress(i,B);
controllerData.squareOn = !Xbox.getButtonPress(i,X);
controllerData.crossOn = !Xbox.getButtonPress(i,A);
controllerData.dpadUpOn = !Xbox.getButtonPress(i,UP);
controllerData.dpadDownOn = !Xbox.getButtonPress(i,DOWN);
controllerData.dpadLeftOn = !Xbox.getButtonPress(i,LEFT);
controllerData.dpadRightOn = !Xbox.getButtonPress(i,RIGHT);
controllerData.startOn = !Xbox.getButtonPress(i,START);
controllerData.selectOn = !Xbox.getButtonPress(i,BACK);
controllerData.homeOn = !Xbox.getButtonPress(i,XBOX);
controllerData.l1On = !Xbox.getButtonPress(i,L1);
controllerData.l2On = !Xbox.getButtonPress(i,L2);
controllerData.l3On = !Xbox.getButtonPress(i,L3);
controllerData.r1On = !Xbox.getButtonPress(i,R1);
controllerData.r2On = !Xbox.getButtonPress(i,R2);
controllerData.r3On = !Xbox.getButtonPress(i,R3);
// And return the data!
return controllerData;
}
void loop(){
// Always be getting fresh data
dataForController_t controllerData = getControllerData();
setControllerData(controllerData);
Usb.Task();
if(Xbox.XboxReceiverConnected){
for (uint8_t i = 0; i < 4; i++){
if (Xbox.Xbox360Connected*){*
//Add code here to do handle connected controler*
}*
}*
}*
}[/quote]* i is declared under the Usb.Task(), i=number of 360 controllers connected, i has to be equal to or less than 4 i am not sure why its going all wacky
Yes, but it is declared and valued as part of a for loop initialisation. As such it will not be in scope outside of that for loop unless it is passed as a parameter to a function, which it isn't.
Yes, but it is declared and valued as part of a for loop initialisation. As such it will not be in scope outside of that for loop unless it is passed as a parameter to a function, which it isn't.
i=number of 360 controllers connected, i has to be equal to or less than 4
Unless you have 5 controllers connected I suspect that the value of i must be less than 4 rather than less than or equal to 4.
What do you want to do with the data from the controllers, how is it stored and how is it accessed ? The getControllerData() function seems to collect the data but you are not telling it which controller to look at when it is called. The data seems to be stored in the controllerData structure but how does the program know which controller it relates to and how would you access it later ?
You could call the getControllerData() function with a parameter of i, the controller number but as far as I can see the data retrieved from controller i is not stored in a way that relates to that particular controller. One problem here is that most people will not have the same hardware and libraries as you which makes helping difficult. Do the libraries that you are using come with any example programs ?
the usb host shield has examples, which i included the necessary coding for the xbox receiver part, but the unojoy has examples but are related to things that plug into the digital pins.
edit: Keep getting one error, apparently its cause one of my commands is not in setup loop or somethin