#include <Keypad.h>
#include <Joystick.h>
#define NUMROWS 5
#define NUMCOLS 5
#define ENABLE_PULLUPS
byte buttons[NUMROWS][NUMCOLS] = {
{0,1,2,3,4},
{5,6,7,8,9},
{10,11,12,13,14},
{15,16,17,18,19},
{20,21,22,23,24},
};
Joystick_ Joystick;
int zAxis_ = 0;
int xAxis_ = 0;
int yAxis_ = 0;
int RzAxis_ = 0;
const bool initAutoSendState = false;
byte rowPins[NUMROWS] = {1,0,2,3,4};
byte colPins[NUMCOLS] = {5,6,7,8,9};
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
void setup()
{
Joystick.begin();
}
void loop(){
// Fren
zAxis_ = analogRead(A1);
zAxis_ = map(zAxis_,0,255,0,255);
Joystick.setZAxis(zAxis_);
// Direksiyon
xAxis_ = analogRead(A3);
xAxis_ = map(xAxis_,0,138,0,255);
Joystick.setXAxis(xAxis_);
// Debriyaj
RzAxis_ = analogRead(A0);
RzAxis_ = map(RzAxis_,0,100,0,255);
Joystick.setRzAxis(RzAxis_);
// Gaz
yAxis_ = analogRead(A2);
yAxis_ = map(yAxis_,0,255,0,255);
Joystick.setYAxis(yAxis_);
delay (50);
CheckAllButtons();
}
void CheckAllButtons(void) {
if (buttbx.getKeys())
{
for (int i=0; i<LIST_MAX; i++)
{
if ( buttbx.key.stateChanged )
{
switch (buttbx.key.kstate) {
case PRESSED:
case HOLD:
Joystick.setButton(buttbx.key.kchar, 1);
break;
case RELEASED:
case IDLE:
Joystick.setButton(buttbx.key.kchar, 0);
break;
}
}
}
}
}