Hey guys,
I'm building a steering wheel for my T300 and i'm missing the paddle clutch on the wheel.
Currently I have this sketch on my arduino nano:
_____
byte wheelState [8]; // local push-buttons state saved here
volatile byte pos;
void setup (void) {
DDRB &= B11110000; // digital pins 8,9,11 used as inputs. 10 - SS also input
PORTB |= B00001011; // 8,9,11 - pull-up to +VCC via internal 100k resistors.
DDRC &= B11000000; // pins 14-19 (A0 - A5) also used as digital inputs
PORTC |= B00111111; // pulled-up to +VCC via internal 100k resistors
DDRD &= B00100000; // digital pins 0,1,3,4,6,7 are inputs for buttons. 2 - also input - for external interrupt 0
PORTD |= B11011011; // 0,1,3,4,6,7 pulled-up to +VCC via internal 100k resistors
wheelState[0] = B11010001; // T300 PS wheel first data byte
wheelState[1] = B11111111; // second data byte - buttons
wheelState[2] = B11111111; // third data byte - buttons
wheelState[3] = B11111111; // this and below - not used, but wheelbase reads all 8 bytes...
wheelState[4] = B11111111;
wheelState[5] = B11111111;
wheelState[6] = B11111111;
wheelState[7] = B11111111;
//Serial.begin(9600); // Arduino debug console - occupies pins RX (0) and TX (1) on Uno
pinMode(MISO, OUTPUT); // arduino is a slave device
SPCR |= _BV(SPE); // Enables the SPI when 1
SPCR |= _BV(SPIE); // Enables the SPI interrupt when 1
// interrupt for SS rising edge. Arduino Uno Pin10 must be connected to Pin2!!!
attachInterrupt (0, ss_rising, RISING);
}
// Interrupt0 (external, pin 2) - prepare to start the transfer
void ss_rising () {
SPDR = wheelState[0]; // load first byte into SPI data register
pos = 1;
}
// SPI interrupt routine
ISR (SPI_STC_vect) {
SPDR = wheelState[pos++]; // load the next byte to SPI output register and return.
}
void loop() {
// scan the button presses and save that to wheelState array. Data transfer to wheelbase is interrupt-driven above.
//wheelState[0] - always constant for T300 PS wheel
wheelState[1] = ((PIND & B11000000) >> 1) | ((PINB & B00000010) << 3) | ((PIND & B00000001) << 3) | ((PINB & B00000001) << 2) | ((PINB & B00001000) >> 2) | ((PIND & B00010000) >> 4) | B10000000;
wheelState[2] = ((PIND & B00000010) << 6) | ((PINC & B00100000) << 1) | ((PINC & B00001000) << 2) | ((PIND & B00001000) << 1) | ((PINC & B00000111) << 1) | ((PINC & B00010000) >> 4);
}
_____
Since I'm pretty new to arduino, I don't know what code I should put to make my potentionmeter work like a clutch.
I've been looking for sometime and I found this code to make a potentionmeter work, but I'm not sure if this will work with the code on top:
_____
#include <Joystick.h>
Joystick_ Joystick;
int Throttle_ = 0;
const bool initAutoSendState = true;
void setup()
{
Joystick.begin();
}
void loop(){
Throttle_ = analogRead(A4);
Throttle_ = map(Throttle_,1023,0,255,0);
Joystick.setThrottle(Throttle_);
delay (50);
}
_____
Can somebody help me with this?
Thank you.
I'm building a steering wheel for my T300 and i'm missing the paddle clutch on the wheel.
Currently I have this sketch on my arduino nano:
_____
byte wheelState [8]; // local push-buttons state saved here
volatile byte pos;
void setup (void) {
DDRB &= B11110000; // digital pins 8,9,11 used as inputs. 10 - SS also input
PORTB |= B00001011; // 8,9,11 - pull-up to +VCC via internal 100k resistors.
DDRC &= B11000000; // pins 14-19 (A0 - A5) also used as digital inputs
PORTC |= B00111111; // pulled-up to +VCC via internal 100k resistors
DDRD &= B00100000; // digital pins 0,1,3,4,6,7 are inputs for buttons. 2 - also input - for external interrupt 0
PORTD |= B11011011; // 0,1,3,4,6,7 pulled-up to +VCC via internal 100k resistors
wheelState[0] = B11010001; // T300 PS wheel first data byte
wheelState[1] = B11111111; // second data byte - buttons
wheelState[2] = B11111111; // third data byte - buttons
wheelState[3] = B11111111; // this and below - not used, but wheelbase reads all 8 bytes...
wheelState[4] = B11111111;
wheelState[5] = B11111111;
wheelState[6] = B11111111;
wheelState[7] = B11111111;
//Serial.begin(9600); // Arduino debug console - occupies pins RX (0) and TX (1) on Uno
pinMode(MISO, OUTPUT); // arduino is a slave device
SPCR |= _BV(SPE); // Enables the SPI when 1
SPCR |= _BV(SPIE); // Enables the SPI interrupt when 1
// interrupt for SS rising edge. Arduino Uno Pin10 must be connected to Pin2!!!
attachInterrupt (0, ss_rising, RISING);
}
// Interrupt0 (external, pin 2) - prepare to start the transfer
void ss_rising () {
SPDR = wheelState[0]; // load first byte into SPI data register
pos = 1;
}
// SPI interrupt routine
ISR (SPI_STC_vect) {
SPDR = wheelState[pos++]; // load the next byte to SPI output register and return.
}
void loop() {
// scan the button presses and save that to wheelState array. Data transfer to wheelbase is interrupt-driven above.
//wheelState[0] - always constant for T300 PS wheel
wheelState[1] = ((PIND & B11000000) >> 1) | ((PINB & B00000010) << 3) | ((PIND & B00000001) << 3) | ((PINB & B00000001) << 2) | ((PINB & B00001000) >> 2) | ((PIND & B00010000) >> 4) | B10000000;
wheelState[2] = ((PIND & B00000010) << 6) | ((PINC & B00100000) << 1) | ((PINC & B00001000) << 2) | ((PIND & B00001000) << 1) | ((PINC & B00000111) << 1) | ((PINC & B00010000) >> 4);
}
_____
Since I'm pretty new to arduino, I don't know what code I should put to make my potentionmeter work like a clutch.
I've been looking for sometime and I found this code to make a potentionmeter work, but I'm not sure if this will work with the code on top:
_____
#include <Joystick.h>
Joystick_ Joystick;
int Throttle_ = 0;
const bool initAutoSendState = true;
void setup()
{
Joystick.begin();
}
void loop(){
Throttle_ = analogRead(A4);
Throttle_ = map(Throttle_,1023,0,255,0);
Joystick.setThrottle(Throttle_);
delay (50);
}
_____
Can somebody help me with this?
Thank you.