Hello all, I am very new and have just been unable to find exactly what I need to make my Arduino Uno board pins activate with the arrows from my xbox controller. I am using the HAT sketch where it activates the lights on the drawing on my screen. I have the controller working and activating the lights. Now the problem comes when I try to make the arrows also turn on and off pins on my board. Specifically pins 8,9,10 and 11. Bellow I have included the current code I am running in processing. Any help would be very appreciated!
import cc.arduino.*;
import org.firmata.*;
import processing.serial.*;
/**
Demonstrates how to get the input from a 'hat' control.
The hat switch is a simple digital joystick with 4 switches,
up, down, left and right. This sketch demonstrates how you
might get the hat inputs. You will need to create your own
configuration file.
for Processing V3
(c) 2020 Peter Lager
*/
import net.java.games.input.*;
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui.*;
ControlIO control;
Configuration config;
ControlDevice device;
ControlHat hat;
Arduino arduino;
// Variables to hold hat inputs
boolean hat_left, hat_right, hat_up, hat_down;
float hat_x, hat_y;
// Variables for hat drawing only
float hx = 90, hy = 90;
float hrad = 70, hbrad = 0.7*hrad, hbsize= 0.15 *hrad;
// Mikes added variables
boolean hat_leftstate=false;
boolean hat_rightstate=false;
boolean hat_upstate=false;
boolean hat_downstate=false;
void setup() {
size(200, 280);
surface.setTitle("GCP Cooliehat example");
arduino = new Arduino(this, Arduino.list()[0], 57600);
// Initialise the ControlIO
control = ControlIO.getInstance(this);
// Find a device that matches the configuration file
device = control.getMatchedDevice("hat-config");
if (device == null) {
println("No suitable device configured");
System.exit(-1); // End the program NOW!
}
hat = device.getHat("HAT");
textSize(16);
for (int i = 8; i <= 11; i++)
arduino.pinMode(i, Arduino.OUTPUT);
//set pins to outputs
}
void draw() {
getUserInput();
background(220);
// ===========================================
// Hat face
stroke(40, 40, 200);
strokeWeight(1.5);
fill(200, 200, 250);
ellipse(hx, hy, 2*hrad, 2*hrad);
// Hat direction buttons
stroke(0);
strokeWeight(0.9);
fill(button_color(hat_left));
ellipse(hx - hbrad, hy, hbsize * 2, hbsize * 2);
fill(button_color(hat_right));
ellipse(hx + hbrad, hy, hbsize * 2, hbsize * 2);
fill(button_color(hat_up));
ellipse(hx, hy - hbrad, hbsize * 2, hbsize * 2);
fill(button_color(hat_down));
ellipse(hx, hy + hbrad, hbsize * 2, hbsize * 2);
// Hat direction values
fill(0);
text("X: " + hat_x, 20, 200, 200, 20);
text("Y: " + hat_y, 20, 230, 200, 20);
}
int button_color(boolean pressed) {
return pressed ? 0xffee2222 : 0xff771111;
}
// Poll for user input called from the draw() method.
public void getUserInput() {
hat_left = hat.left();
hat_right = hat.right();
hat_up = hat.up();
hat_down = hat.down();
hat_x = hat.getX();
hat_y = hat.getY();
}