Hey everyone! I recently picked up an SNES Super Advantage controller and have set up an interface with it using a slightly modified version of this code
Now, outside of the general turbo and slow (basically, turbo for Start) features the controller has a few unique functions: fully automatic turbo for each individual button (except Start and Select) and sliders to adjust the speed of the turbo.
Considering that the controller's output is 2 bytes with the state of each button, and the fact that it can read every button being pressed simultaneously -- except up/down and left/right, which I obviously can't test without taking the thing apart -- I think this would be a great controller for a sequencer.
My very basic idea would be to hook up a speaker and use a tone generating library to assign each key a different and specific sound. The automatic turbo buttons/sliders could be used to make repeating beats, and the buttons can be used as a keyboard-style input. The joystick could be used to adjust pitch or volume.
Sounds like it will work fine. Here is a modified version of that NES code with 'if statements' that you can put tone commands into:
byte ud = 127;
byte lr = 127;
byte st = 0;
byte sl = 0;
byte a = 0;
byte b = 0;
int latch = 2; // set the latch pin
int clock = 3; // set the clock pin
int datin = 4;// set the data in pin
byte controller_data = 0;
void setup() {
Serial.begin(9600);
pinMode(latch,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(datin,INPUT);
digitalWrite(latch,HIGH);
digitalWrite(clock,HIGH);
}
/* THIS READS DATA FROM THE CONTROLLER */
void controllerRead() {
controller_data = 0;
digitalWrite(latch,LOW);
digitalWrite(clock,LOW);
digitalWrite(latch,HIGH);
delayMicroseconds(2);
digitalWrite(latch,LOW);
controller_data = digitalRead(datin);
for (int i = 1; i <= 7; i ++) {
digitalWrite(clock,HIGH);
delayMicroseconds(2);
controller_data = controller_data << 1;
controller_data = controller_data + digitalRead(datin) ;
delayMicroseconds(4);
digitalWrite(clock,LOW);
}
}
void loop() {
controllerRead();
// if (controller_data==B11101111){
// Serial.println("Button has been Pressed");
//} else {
//Serial.println("Button not pressed");
//}
//for REFERENCE:
//UP = 11110111 bit3
//DOWN=11111011 bit2
//LEFT=11111101 bit1
//RIGHT=11111110 bit0
//SELECT=11011111 bit5
//START=11101111 bit4
//A=01111111 bit7
//B=10111111 bit6
if (bitRead(controller_data,3)==0){
ud = 235;
//Serial.println("up"); //Debug test
}
if (bitRead(controller_data,2)==0){
ud = 1;
//Serial.println("down"); //Debug test
}
if (bitRead(controller_data,1)==0){
lr = 235;
//Serial.println("left"); //Debug test
}
if (bitRead(controller_data,0)==0){
lr = 1;
//Serial.println("right"); //Debug test
}
if (bitRead(controller_data,4)==0){
st = 235;
//Serial.println("start"); //Debug test
}
if (bitRead(controller_data,5)==0){
sl = 235;
//Serial.println("select"); //Debug test
}
if (bitRead(controller_data,7)==0){
a = 235;
//Serial.println("a"); //Debug test
}
if (bitRead(controller_data,6)==0){
b = 235;
//Serial.println("b"); //Debug test
}
Serial.print(246,BYTE); // 240 plus the number of channels
Serial.print(0,BYTE); // button presses
Serial.print(ud,BYTE);
Serial.print(lr,BYTE);
Serial.print(st,BYTE);
Serial.print(sl,BYTE);
Serial.print(a,BYTE);
Serial.print(b,BYTE);
delay(100);
ud = 127;
lr = 127;
st = 127;
sl = 127;
a = 127;
b = 127;
}