#include <Joystick.h>
/*
* This code takes inputs from a 9 pin intellivision controller and converts it into joystick buttons, since all points on disc are just buttons.
* Below is an ec=xample of the intellivision ciontroller layout
*
* +---+---+---+
* X | 1 | 2 | 3 | X
* +---+---+---+
* Y | 4 | 5 | 6 | Z
* +---+---+---+
* | 7 | 8 | 9 |
* +---+---+---+
* | C | 0 | E |
* +---+---+---+
* o p a b c
* n \ | / d
* m - o - e
* l / | \ f
* k j i h g
*
* Mattel DB9 pinout (intv 2)
* ------------- ------------------
* \ 5 4 3 2 1 / \ Gr Wh Bl Bk Yl /
* \ 9 8 7 6 / \ Rd Br Gy Or /
* --------- -------------
*
* Mattel hardwire pinout (intv 1)
* ___________________________________
* | 5 | 4 | 3 | 2 | 1 | 9 | 8 | 7 | 6 |
* -----------------------------------
* Br | R | O | Y| Gnd | B | Bk| G | W
*
* Intellivision (DB9) - Arduino (pins) - pin Array position
* 1 Yellow - D2 - Yellow - (0)
* 2 Black - GND - Black
* 3 Blue - D3 - Blue - (1)
* 4 White - D4 - White - (2)
* 5 Green - D5 - Green - (3)
* 6 Pink - D6 - Orange - (4)
* 7 Grey - D7 - Grey - (5)
* 8 Brown - D8 - Brown - (6)
* 9 Red - D9 - Red - (7)
*
*/
Joystick_ Joystick1;
Joystick_ Joystick2;
// Arduino Micro digital pins
//int myPin1[8]={5,4,3,2,9,8,7,6}; //Intv1 layout
int myPin1[8]={2,3,4,5,6,7,8,9}; //Intv 2 layout
int myPin2[8]={0,0,0,0,0,0,0,0};
unsigned char wire1;
unsigned char wire2;
unsigned char oldwire1=B11111111;
unsigned char buttonstate1;
int ledPin = 13;
bool ledOn = 0;
// Last state of buttons
int lastButtonState1[31] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int lastButtonState2[31] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void setup() {
// put your setup code here, to run once:
// set pin 2-9 as inputy and pull high
for (int t=0; t<8; t++) {
pinMode ( myPin1[t] , INPUT_PULLUP ); // declare led as output
Serial.print(myPin1[t]);Serial.println('.-z.');
digitalWrite(ledPin, LOW); // turn off led
}
Joystick1.begin();
Joystick2.begin();
int done = 0;
}
/*
void printBits(byte myByte){
for(byte mask = 0x80; mask; mask >>= 1){
if(mask & myByte)
Serial.print('1');
else
Serial.print('0');
}
Serial.println('.');
}
*/
void loop() {
// put your main code here, to run repeatedly:
Serial.print("Test Wire In");Serial.println('.');
wire1 = 0;
for (int t=0; t<8; t++) {
Serial.print(digitalRead(myPin1[t]), DEC);Serial.println(".-.");
wire1 |= ((digitalRead(myPin1[t]) == LOW ? 1:0)<<(7-t));
}
delay(10);
Serial.print("Test Wire In");Serial.println('.');
//wire1=10000001; // clear wire byte from Controller 1
wire2=0; // clear wire byte from Controller 2
/*
for(byte mask = 0x80; mask; mask >>= 1){
if(mask & wire1){
Serial.print('1');
}
else{
Serial.print('0');
}
Serial.println('.');
}
*/
// for(int t=0; t<8; t++){
// wire1 != ((digitalRead(myPin1[t])==LOW ? 0:1)<<(7-t)); // read wire from Controller 1
// wire2 != ((digitalRead(myPin2[t])==LOW ? 0:1)<<(7-t)); // read wire from Controller 2
// }
if (wire1 != oldwire1){
//Joystick1.releaseAll();
oldwire1 = wire1;
ledOn = 1-ledOn;
digitalWrite(ledPin, ledOn); //turn off led
}
//currentButtonState1 = wire1;
//wire1='10000101';
/*
Serial.print('wire1');Serial.println('.');
for(int i =0; i < strlen(wire1); i++ ) {
unsigned char c = wire1[i];
// do something with c
if (c == 1){
Serial.print('1');
}
else{
Serial.print('0');
}
}
*/
/*
for(byte mask = 0x80; mask; mask >>= 1){
if(mask & wire1){
Serial.print('x');
}
else{
Serial.print('0');
}
Serial.println('.');
}*/
//printBits(wire);
int done = 0;
/*
for (int index = 0; index < 7; index++)
{
if (wire1 != oldWire1[index]){
Joystick1.setButton(index, LOW);
lastButtonState1[index] = currentButtonState1;
}
}
*/
// side buttons
Serial.println("Test Wire1:");
Serial.println(wire1, BIN);
if ((wire1 & B10000000) == B10000000) {Serial.println("Y");}
if ((wire1 & B01000000) == B01000000) {Serial.println("Bl");}
if ((wire1 & B00100000) == B00100000) {Serial.println("Wh");}
if ((wire1 & B00010000) == B00010000) {Serial.println("Gr");}
if ((wire1 & B00001000) == B00001000) {Serial.println("Or");}
if ((wire1 & B00000100) == B00000100) {Serial.println("Gy");}
if ((wire1 & B00000010) == B00000010) {Serial.println("Br");}
if ((wire1 & B00000001) == B00000001) {Serial.println("Rd");}
//if (wire1 & B00001010 == B00001010){Joystick1.setButton(0, LOW);};done=1;
//if (wire1 & B00001100 == B00000110){Joystick1.setButton(1, LOW);};done=1;
//if (wire1 & B00001100 == B00001100){Joystick1.setButton(2, LOW);};done=1;
switch(wire1) {
case B10000000: Joystick1.setButton(0, LOW); done = 1;break; // X
case B10000001: Joystick1.setButton(1, LOW); done = 1;break; // Y
case B10000010: Joystick1.setButton(2, LOW); done = 1;break; // Z
}
// Key pad
done = 0; //reset indicator to check key pad
switch(wire1){
case B00000001: Joystick1.setButton(3, LOW); done = 1;break; // 1
case B00000010: Joystick1.setButton(4, LOW); done = 1;break; // 2
case B00000011: Joystick1.setButton(5, LOW); done = 1;break; // 3
case B00000100: Joystick1.setButton(6, LOW); done = 1;break; // 4
case B00000101: Joystick1.setButton(7, LOW); done = 1;break; // 5
case B00000110: Joystick1.setButton(8, LOW); done = 1;break; // 6
case B00000111: Joystick1.setButton(9, LOW); done = 1;break; // 7
case B00001000: Joystick1.setButton(10, LOW); done = 1;break; // 8
case B00001001: Joystick1.setButton(11, LOW); done = 1;break; // 9
case B00001010: Joystick1.setButton(12, LOW); done = 1;break; // Clear
case B00001011: Joystick1.setButton(13, LOW); done = 1;break; // 0
case B00001100: Joystick1.setButton(14, LOW); done = 1;break; // Enter
}
// Disk
done = 0; //reset indicator to check Disk
switch(wire1){
case B00001101: Joystick1.setButton(15, LOW); done = 1;break; // a
case B00001110: Joystick1.setButton(16, LOW); done = 1;break; // b
case B00001111: Joystick1.setButton(17, LOW); done = 1;break; // c
case B00010000: Joystick1.setButton(18, LOW); done = 1;break; // d
case B00010001: Joystick1.setButton(19, LOW); done = 1;break; // e
case B00010010: Joystick1.setButton(20, LOW); done = 1;break; // f
case B00010011: Joystick1.setButton(21, LOW); done = 1;break; // g
case B00010100: Joystick1.setButton(22, LOW); done = 1;break; // h
case B00010101: Joystick1.setButton(23, LOW); done = 1;break; // i
case B00010110: Joystick1.setButton(24, LOW); done = 1;break; // j
case B00010111: Joystick1.setButton(25, LOW); done = 1;break; // k
case B00011000: Joystick1.setButton(26, LOW); done = 1;break; // l
case B00011001: Joystick1.setButton(27, LOW); done = 1;break; // m
case B00011010: Joystick1.setButton(28, LOW); done = 1;break; // n
case B00011011: Joystick1.setButton(29, LOW); done = 1;break; // o
case B00011100: Joystick1.setButton(30, LOW); done = 1;break; // p
}
}
Comments
Please log in or sign up to comment.