Hello,
I am very hopeless with coding, I used to understand a bit more, years passed and now I am a complete rookie.
In essence I am trying to make this project from instructable, where this guy makes this perfect button board for video games, in my case I need rotary encoders instead of pots, and after spending hours trying to Frankenstein his script with others I find online, I decided to ask for help to you guys (Been reading the forum a lot the last 2/3 days)
Here is the script;
This code is for a teensy 3.1 used in my green russian control board
You must select the teensy board in Tools and change USB Type to Joystick
*/
//How many buttons I'm using, must equal amount of values in following array
#define NUM_BUTTONS 14
//Which pins I have attached to my buttons
int buttonList[NUM_BUTTONS] = {2,3,4,5,6,7,8,9,10,11,12,14,15,16};
//Led intensity, so super bright LEDS aren't shining in our eyes
#define INTENSITY 200
void setup() {
//This makes it so the states are send by us manually
Joystick.useManualSend(true);
//Declare button pins as input with the internal pullup resistor on
for (int i = 0; i < NUM_BUTTONS; i++) {
pinMode(buttonList, INPUT_PULLUP);
}
//Declare our LED pins as outputs
pinMode(17, OUTPUT);
pinMode(18, OUTPUT);
pinMode(19, OUTPUT);
pinMode(20, OUTPUT);
}
void loop() {
//Read our analogue pots
//Remember that the analogue pin numbers are different than the digital ones!
Joystick.sliderLeft(analogRead(7));
Joystick.sliderRight(analogRead(8));
//Read our button states
for (int i = 0; i < NUM_BUTTONS; i++) {
if (digitalRead(buttonList) == HIGH) { //Check to see if pin is HIGH
Joystick.button(i + 1, 0); //If pin is HIGH, button isn't pressed, so send 0
} else {
Joystick.button(i + 1, 1); //If pin is LOW, button is pressed, so send 1
}
}
//Special case for LED status lights
//Check status of button and change LED accordingly
if (digitalRead(12) == LOW) //Check if button is pressed/switch flipped
analogWrite(17, INTENSITY); //Set corresponding LED pin to intensity level
else
analogWrite(17, 0); //Otherwise turn off
if (digitalRead(7) == LOW) //Same for other pins
analogWrite(18, INTENSITY);
else
analogWrite(18, 0);
if (digitalRead(9) == LOW)
analogWrite(19, INTENSITY);
else
analogWrite(19, 0);
if (digitalRead(11) == LOW)
analogWrite(20, INTENSITY);
else
analogWrite(20, 0);
Joystick.send_now(); //Send control states
delay(5); //Slow things down a bit
}
I don't want to sound like I am demanding for someone to do my homework, but I am really stuck. I managed to have the encoders rotation to print a text on the serial monitor, but I don't know how to have a joypad press rather than a text print, again, I am at almost 0 with this.
If anyone can help I would much appreciate it!
Grazie
I am very hopeless with coding, I used to understand a bit more, years passed and now I am a complete rookie.
In essence I am trying to make this project from instructable, where this guy makes this perfect button board for video games, in my case I need rotary encoders instead of pots, and after spending hours trying to Frankenstein his script with others I find online, I decided to ask for help to you guys (Been reading the forum a lot the last 2/3 days)
Here is the script;
This code is for a teensy 3.1 used in my green russian control board
You must select the teensy board in Tools and change USB Type to Joystick
*/
//How many buttons I'm using, must equal amount of values in following array
#define NUM_BUTTONS 14
//Which pins I have attached to my buttons
int buttonList[NUM_BUTTONS] = {2,3,4,5,6,7,8,9,10,11,12,14,15,16};
//Led intensity, so super bright LEDS aren't shining in our eyes
#define INTENSITY 200
void setup() {
//This makes it so the states are send by us manually
Joystick.useManualSend(true);
//Declare button pins as input with the internal pullup resistor on
for (int i = 0; i < NUM_BUTTONS; i++) {
pinMode(buttonList, INPUT_PULLUP);
}
//Declare our LED pins as outputs
pinMode(17, OUTPUT);
pinMode(18, OUTPUT);
pinMode(19, OUTPUT);
pinMode(20, OUTPUT);
}
void loop() {
//Read our analogue pots
//Remember that the analogue pin numbers are different than the digital ones!
Joystick.sliderLeft(analogRead(7));
Joystick.sliderRight(analogRead(8));
//Read our button states
for (int i = 0; i < NUM_BUTTONS; i++) {
if (digitalRead(buttonList) == HIGH) { //Check to see if pin is HIGH
Joystick.button(i + 1, 0); //If pin is HIGH, button isn't pressed, so send 0
} else {
Joystick.button(i + 1, 1); //If pin is LOW, button is pressed, so send 1
}
}
//Special case for LED status lights
//Check status of button and change LED accordingly
if (digitalRead(12) == LOW) //Check if button is pressed/switch flipped
analogWrite(17, INTENSITY); //Set corresponding LED pin to intensity level
else
analogWrite(17, 0); //Otherwise turn off
if (digitalRead(7) == LOW) //Same for other pins
analogWrite(18, INTENSITY);
else
analogWrite(18, 0);
if (digitalRead(9) == LOW)
analogWrite(19, INTENSITY);
else
analogWrite(19, 0);
if (digitalRead(11) == LOW)
analogWrite(20, INTENSITY);
else
analogWrite(20, 0);
Joystick.send_now(); //Send control states
delay(5); //Slow things down a bit
}
I don't want to sound like I am demanding for someone to do my homework, but I am really stuck. I managed to have the encoders rotation to print a text on the serial monitor, but I don't know how to have a joypad press rather than a text print, again, I am at almost 0 with this.
If anyone can help I would much appreciate it!
Grazie