Hardware Making a custom pro controller with a teensy board?

Alpha_GX

Well-Known Member
OP
Newcomer
Joined
Dec 11, 2016
Messages
45
Trophies
0
Age
28
XP
384
Country
France
Hi all, I just happened to use ShinyQuagsire splat post printer with a teensy++ 2.0, and as I saw several people making their own bots for the switch I wondered if there was a way to turn the tennsy board in an actual pro controller, I mean taking in some analog input and button press on the board and made them being recognize by the switch as controller input. The ideal would be something like:

if button(0) is pressed {
Switch_button(0) is pressed
}

First I though I could do that myself, but after looking at the source code, I realized that I didn't understood half of it, I have a very limited knowledge, hence I come here asking for help.
I also happen to find this project: https://github.com/grantal/teensy-switch
But don't understand how to get it working (I installed the cores but then I don't understand if there are any special step required)
Anyways I hope some people will be able to help me.
Thanks in advance
 

mattytrog

You don`t want to listen to anything I say.
Member
Joined
Apr 27, 2018
Messages
3,708
Trophies
0
Age
48
XP
4,328
Country
United Kingdom
You could use a teensy, with an HC05 bluetooth module. Program the HC05 up with a FTDI usb to serial maybe? Will look into this.
 
  • Like
Reactions: peteruk

fluffymadness

Member
Newcomer
Joined
Mar 30, 2019
Messages
8
Trophies
0
Age
124
XP
234
Country
Austria
@Alpha_GX. gbatemp.net/threads/diy-switch-fightstick.534779/ Its for a pro micro not teensy. Haven't added any true analog support, just fake analog since its considered for fightsticks.
Its completely finished. You'd just need to connect buttons.
 
Last edited by fluffymadness,

Alpha_GX

Well-Known Member
OP
Newcomer
Joined
Dec 11, 2016
Messages
45
Trophies
0
Age
28
XP
384
Country
France
@Alpha_GX. gbatemp.net/threads/diy-switch-fightstick.534779/ Its for a pro micro not teensy. Haven't added any true analog support, just fake analog since its considered for fightsticks.
Its completely finished. You'd just need to connect buttons.
Thanks, I'll looks into it and see what I can do with it :)
 

Alpha_GX

Well-Known Member
OP
Newcomer
Joined
Dec 11, 2016
Messages
45
Trophies
0
Age
28
XP
384
Country
France
I tried to verify the code with the arduino software for the teensy 2.0 and 2.0++ boards and didn't got any results, as it work for most other Arduino cards, I guess it's not an error on my end, but the board that are incompatiles rn.
Here is the error message if you wanna take a look:
Arduino : 1.8.9 (Windows 10), TD: 1.46, Carte : "Teensy++ 2.0, Serial, 16 MHz, US English"

Les options de compilation ont été modifiées, tout sera recompilé
In file included from D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\libraries\LUFA/LUFA/LUFA/Drivers/USB/Core/ConfigDescriptors.h:56:0,

from D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\libraries\LUFA/LUFA/LUFA/Drivers/USB/USB.h:389,

from D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\libraries\LUFA/LUFA.c.inc:43,

from D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\sketch\LUFA.c:3:

D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\libraries\LUFA/LUFA/LUFA/Drivers/USB/Core/HostStandardReq.h:281:20: warning: 'USB_Host_SendControlRequest_PRV' declared 'static' but never defined [-Wunused-function]

static uint8_t USB_Host_SendControlRequest_PRV(void* const BufferPtr);

^

D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\libraries\LUFA/LUFA/LUFA/Drivers/USB/Core/HostStandardReq.h:282:20: warning: 'USB_Host_WaitForIOS' declared 'static' but never defined [-Wunused-function]

static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType);

^

d:\users\yoyo\desktop\teensy\arduino-1.8.9\hardware\tools\avr\avr\include\stdlib.h: In function 'malloc':

D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\teensy\avr\cores\teensy\malloc.c:134:7: warning: 'sfp2' may be used uninitialized in this function [-Wmaybe-uninitialized]

if (sfp2)

^

D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\teensy\avr\cores\teensy\malloc.c:76:40: note: 'sfp2' was declared here

struct __freelist *fp1, *fp2, *sfp1, *sfp2;

^

D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\teensy\avr\cores\teensy\malloc.c:135:20: warning: 'sfp1' may be used uninitialized in this function [-Wmaybe-uninitialized]

sfp2->nx = sfp1->nx;

^

D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\teensy\avr\cores\teensy\malloc.c:76:33: note: 'sfp1' was declared here

struct __freelist *fp1, *fp2, *sfp1, *sfp2;

^

D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534/core\core.a(usb.c.o): In function `__vector_10':

d:\users\yoyo\desktop\teensy\arduino-1.8.9\hardware\teensy\avr\cores\usb_serial/usb.c:278: multiple definition of `__vector_10'

D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\sketch\LUFA.c.o:d:\users\yoyo\desktop\teensy\arduino-1.8.9\libraries\lufa\lufa\lufa\drivers\usb\core\AVR8/USBInterrupt_AVR8.c:78: first defined here

d:/users/yoyo/desktop/teensy/arduino-1.8.9/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

collect2.exe: error: ld returned 1 exit status

Plusieurs bibliothèque trouvées pour "Bounce2.h"
Utilisé : D:\Users\Yoyo\Documents\Arduino\libraries\Bounce2
Non utilisé : D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\teensy\avr\libraries\Bounce2
Erreur de compilation pour la carte Teensy++ 2.0

Ce rapport pourrait être plus détaillé avec
l'option "Afficher les résultats détaillés de la compilation"
activée dans Fichier -> Préférences.
Arduino : 1.8.9 (Windows 10), TD: 1.46, Carte : "Teensy++ 2.0, Serial, 16 MHz, US English"

D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\arduino-builder -dump-prefs -logger=machine -hardware D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware -hardware D:\Users\Yoyo\AppData\Local\Arduino15\packages -tools D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\tools-builder -tools D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\tools\avr -tools D:\Users\Yoyo\AppData\Local\Arduino15\packages -built-in-libraries D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\libraries -libraries D:\Users\Yoyo\Documents\Arduino\libraries -fqbn=teensy:avr:teensypp2:usb=serial,speed=16,keys=en-us -ide-version=10809 -build-path D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534 -warnings=none -build-cache D:\Users\Yoyo\AppData\Local\Temp\arduino_cache_136512 -verbose D:\Users\Yoyo\Desktop\Teensy\ATMega32U4-Switch-Fightstick-Teensy2__ver\ATMega32U4-Switch-Fightstick-Teensy2__ver.ino
D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\arduino-builder -compile -logger=machine -hardware D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware -hardware D:\Users\Yoyo\AppData\Local\Arduino15\packages -tools D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\tools-builder -tools D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\tools\avr -tools D:\Users\Yoyo\AppData\Local\Arduino15\packages -built-in-libraries D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\libraries -libraries D:\Users\Yoyo\Documents\Arduino\libraries -fqbn=teensy:avr:teensypp2:usb=serial,speed=16,keys=en-us -ide-version=10809 -build-path D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534 -warnings=none -build-cache D:\Users\Yoyo\AppData\Local\Temp\arduino_cache_136512 -verbose D:\Users\Yoyo\Desktop\Teensy\ATMega32U4-Switch-Fightstick-Teensy2__ver\ATMega32U4-Switch-Fightstick-Teensy2__ver.ino
Using board 'teensypp2' from platform in folder: D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\teensy\avr
Using core 'teensy' from platform in folder: D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\teensy\avr
Detecting libraries used...
"D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy/../tools/avr/bin/avr-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -fno-exceptions -fpermissive -felide-constructors -std=gnu++11 -mmcu=at90usb1286 -DTEENSYDUINO=146 -DARDUINO_ARCH_AVR -DARDUINO=10809 -DF_CPU=16000000L -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy\\avr\\cores\\teensy" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\ATMega32U4-Switch-Fightstick-Teensy2__ver.ino.cpp" -o nul
"D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy/../tools/avr/bin/avr-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -fno-exceptions -fpermissive -felide-constructors -std=gnu++11 -mmcu=at90usb1286 -DTEENSYDUINO=146 -DARDUINO_ARCH_AVR -DARDUINO=10809 -DF_CPU=16000000L -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy\\avr\\cores\\teensy" "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\libraries\\LUFA" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\ATMega32U4-Switch-Fightstick-Teensy2__ver.ino.cpp" -o nul
"D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy/../tools/avr/bin/avr-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -fno-exceptions -fpermissive -felide-constructors -std=gnu++11 -mmcu=at90usb1286 -DTEENSYDUINO=146 -DARDUINO_ARCH_AVR -DARDUINO=10809 -DF_CPU=16000000L -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy\\avr\\cores\\teensy" "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\libraries\\LUFA" "-ID:\\Users\\Yoyo\\Documents\\Arduino\\libraries\\Bounce2\\src" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\ATMega32U4-Switch-Fightstick-Teensy2__ver.ino.cpp" -o nul
Using cached library dependencies for file: D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\sketch\Descriptors.c
Using cached library dependencies for file: D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\sketch\Joystick.c
Using cached library dependencies for file: D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\sketch\LUFA.c
Using cached library dependencies for file: D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\libraries\LUFA\LUFACDCSerial.cpp
Using cached library dependencies for file: D:\Users\Yoyo\Documents\Arduino\libraries\Bounce2\src\Bounce2.cpp
Generating function prototypes...
"D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy/../tools/avr/bin/avr-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -fno-exceptions -fpermissive -felide-constructors -std=gnu++11 -mmcu=at90usb1286 -DTEENSYDUINO=146 -DARDUINO_ARCH_AVR -DARDUINO=10809 -DF_CPU=16000000L -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy\\avr\\cores\\teensy" "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\libraries\\LUFA" "-ID:\\Users\\Yoyo\\Documents\\Arduino\\libraries\\Bounce2\\src" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\ATMega32U4-Switch-Fightstick-Teensy2__ver.ino.cpp" -o "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compilation du croquis...
"D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy/../tools/precompile_helper" "D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy\\avr/cores/teensy" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534" "D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy/../tools/avr/bin/avr-g++" -x c++-header -Os -g -Wall -ffunction-sections -fdata-sections -MMD -fno-exceptions -fpermissive -felide-constructors -std=gnu++11 -mmcu=at90usb1286 -DTEENSYDUINO=146 -DARDUINO_ARCH_AVR -DARDUINO=10809 -DF_CPU=16000000L -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy\\avr/cores/teensy" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534/pch/Arduino.h" -o "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534/pch/Arduino.h.gch"
Using previously compiled file: D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\pch\Arduino.h.gch

Utilisation du fichier déjà compilé : D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\sketch\Descriptors.c.o
Utilisation du fichier déjà compilé : D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\sketch\LUFA.c.o
Utilisation du fichier déjà compilé : D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\sketch\Joystick.c.o
"D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy/../tools/avr/bin/avr-g++" -c -Os -g -Wall -ffunction-sections -fdata-sections -MMD -fno-exceptions -fpermissive -felide-constructors -std=gnu++11 -mmcu=at90usb1286 -DTEENSYDUINO=146 -DARDUINO_ARCH_AVR -DARDUINO=10809 -DF_CPU=16000000L -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-ID:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534/pch" "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy\\avr\\cores\\teensy" "-ID:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\libraries\\LUFA" "-ID:\\Users\\Yoyo\\Documents\\Arduino\\libraries\\Bounce2\\src" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\ATMega32U4-Switch-Fightstick-Teensy2__ver.ino.cpp" -o "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\ATMega32U4-Switch-Fightstick-Teensy2__ver.ino.cpp.o"
Compiling libraries...
Compiling library "LUFA"
Utilisation du fichier déjà compilé : D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\libraries\LUFA\LUFACDCSerial.cpp.o
Compiling library "Bounce2"
Utilisation du fichier déjà compilé : D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\libraries\Bounce2\Bounce2.cpp.o
Compiling core...
Using precompiled core: D:\Users\Yoyo\AppData\Local\Temp\arduino_cache_136512\core\core_teensy_avr_teensypp2_usb_serial,speed_16,keys_en-us_95c8228d2f6906304bdc79348a5400cb.a
Linking everything together...
"D:\\Users\\Yoyo\\Desktop\\Teensy\\arduino-1.8.9\\hardware\\teensy/../tools/avr/bin/avr-gcc" -Os -Wl,--gc-sections,--relax -mmcu=at90usb1286 -o "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534/ATMega32U4-Switch-Fightstick-Teensy2__ver.ino.elf" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\ATMega32U4-Switch-Fightstick-Teensy2__ver.ino.cpp.o" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\Descriptors.c.o" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\Joystick.c.o" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\sketch\\LUFA.c.o" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\libraries\\LUFA\\LUFACDCSerial.cpp.o" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534\\libraries\\Bounce2\\Bounce2.cpp.o" "D:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534/..\\arduino_cache_136512\\core\\core_teensy_avr_teensypp2_usb_serial,speed_16,keys_en-us_95c8228d2f6906304bdc79348a5400cb.a" "-LD:\\Users\\Yoyo\\AppData\\Local\\Temp\\arduino_build_761534" -lm
D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534/..\arduino_cache_136512\core\core_teensy_avr_teensypp2_usb_serial,speed_16,keys_en-us_95c8228d2f6906304bdc79348a5400cb.a(usb.c.o): In function `__vector_10':

d:\users\yoyo\desktop\teensy\arduino-1.8.9\hardware\teensy\avr\cores\usb_serial/usb.c:278: multiple definition of `__vector_10'

D:\Users\Yoyo\AppData\Local\Temp\arduino_build_761534\sketch\LUFA.c.o:d:\users\yoyo\desktop\teensy\arduino-1.8.9\libraries\lufa\lufa\lufa\drivers\usb\core\AVR8/USBInterrupt_AVR8.c:78: first defined here

d:/users/yoyo/desktop/teensy/arduino-1.8.9/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

collect2.exe: error: ld returned 1 exit status

Plusieurs bibliothèque trouvées pour "Bounce2.h"
Utilisé : D:\Users\Yoyo\Documents\Arduino\libraries\Bounce2
Non utilisé : D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\hardware\teensy\avr\libraries\Bounce2
Utilisation de la bibliothèque LUFA prise dans le dossier : D:\Users\Yoyo\Desktop\Teensy\arduino-1.8.9\libraries\LUFA (legacy)
Utilisation de la bibliothèque Bounce2 version 2.52 dans le dossier: D:\Users\Yoyo\Documents\Arduino\libraries\Bounce2
Erreur de compilation pour la carte Teensy++ 2.0
So if I were to switch to a Pro Micro board, is this one good ? https://fr.aliexpress.com/item/Free...-Module-with-2-row-pin-header/1348800135.html
 

fluffymadness

Member
Newcomer
Joined
Mar 30, 2019
Messages
8
Trophies
0
Age
124
XP
234
Country
Austria
Looks pretty similar to what I bought. I think the clones are pretty much the same. I have the model with 5v/16mhz.

edit: Yeah...I guess there's some incompatibility there with the teensy
 
Last edited by fluffymadness,

Alpha_GX

Well-Known Member
OP
Newcomer
Joined
Dec 11, 2016
Messages
45
Trophies
0
Age
28
XP
384
Country
France
Well thanks, I'll buy one and see how it goes in about 50 days. ;-;
I'm still open to others solution if anyone else happen to read this.
 

fluffymadness

Member
Newcomer
Joined
Mar 30, 2019
Messages
8
Trophies
0
Age
124
XP
234
Country
Austria
That's the thing with usb libraries. They are very microcontroller specific :/ The teensy 3.0 for example also has its own usb stack. I played around with some xinput stuff before i moved to the pro micro.
There's also a lightweight usb stack for stm microcontrollers. You kinda have to port some code, switching usb stack, when using a different microcontroller.
The basic function of the controller itself is just a hid usb descriptor, and some binary data that contains the pressed buttons.

edit: if you want to do a bit of reading: eleccelerator.com/tutorial-about-usb-hid-report-descriptors/
 
Last edited by fluffymadness,
  • Like
Reactions: Alpha_GX

Alpha_GX

Well-Known Member
OP
Newcomer
Joined
Dec 11, 2016
Messages
45
Trophies
0
Age
28
XP
384
Country
France
Hey I actually got it to work, I looked again in the Joystick.c file and by modifying the content of void GetNextReport and cleaning up the useles stuff, I manage to make everything work.
Here is how it looks like now:
int LR = 0;

---------------------------------------------------------------------------------------------------------

void GetNextReport(USB_JoystickReport_Input_t* const ReportData) {

// Prepare an empty report
memset(ReportData, 0, sizeof(USB_JoystickReport_Input_t));
ReportData->LX = STICK_CENTER;
ReportData->LY = STICK_CENTER;
ReportData->RX = STICK_CENTER;
ReportData->RY = STICK_CENTER;
ReportData->HAT = HAT_CENTER;

int joy1y=map(analogRead(2),948,1025,250,5);
int joy1x=map(analogRead(3),948,1025,5,250);
ReportData->LY = joy1y;
ReportData->LX = joy1x;

int joy2y=analogRead(0);
if (joy2y < 970) {
ReportData->Button |= SWITCH_A;
}
if (joy2y > 1010) {
ReportData->Button |= SWITCH_B;
}
int joy2x=analogRead(1);
if (joy2x < 970) {
ReportData->Button |= SWITCH_R;
}
if (joy2x > 1020) {
ReportData->Button |= SWITCH_ZL;
}
if (LR < 100){
if (!(LR % 2)) {
ReportData->Button |= SWITCH_L | SWITCH_R;
}
}

LR += 1;

ReportData->Button |= SWITCH_CAPTURE;
memcpy(&last_report, ReportData, sizeof(USB_JoystickReport_Input_t));
}
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdint.h>
#include "analog.h"
------------------------------------------------------------------------------------------------

static uint8_t aref = (1<<REFS0); // default to AREF = Vcc

int16_t analogRead(uint8_t pin)
{
#if defined(__AVR_ATmega32U4__)
static const uint8_t PROGMEM pin_to_mux[] = {
0x00, 0x01, 0x04, 0x05, 0x06, 0x07,
0x25, 0x24, 0x23, 0x22, 0x21, 0x20};
if (pin >= 12) return 0;
return adc_read(pgm_read_byte(pin_to_mux + pin));
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
if (pin >= 8) return 0;
return adc_read(pin);
#else
return 0;
#endif
}

// Mux input
int16_t adc_read(uint8_t mux)
{
#if defined(__AVR_AT90USB162__)
return 0;
#else
uint8_t low;

ADCSRA = (1<<ADEN) | ADC_PRESCALER; // enable ADC
ADCSRB = (1<<ADHSM) | (mux & 0x20); // high speed mode
ADMUX = aref | (mux & 0x1F); // configure mux input
ADCSRA = (1<<ADEN) | ADC_PRESCALER | (1<<ADSC); // start the conversion
while (ADCSRA & (1<<ADSC)) ; // wait for result
low = ADCL; // must read LSB first
return (ADCH << 8) | low; // must read MSB only once!
#endif
}

long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
The controls are a bit special cause it's only based on two analog read, but that's my controller limitation, nothing with the code itself.
I'll probably do a little tiny write up so people that will have the same problems as me would find a quick answer.
Guess I can close the thread now ¯\_(ツ)_/¯
Edit: I don't know how to do that
 
Last edited by Alpha_GX,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    The Real Jdbye @ The Real Jdbye: sure, it can be hands free