This is a complete spinner to use with an arcade cabinet. I use this with Mame. Even if there are other design. I had to develop it by zero.
What you need.
N°1 Leonardo Micro ATmega32U4 16MHz 5V Replace ATmega328 Arduino Mini Stock TE463
http://www.ebay.it/itm/322097722501?_trksid=p2060353.m1438.l2649&ssPageName=STRK%3AMEBIDX%3AIT
N°1 Incrementale Ottica Codificatore a Rotazione 400 Impulsi / REV Rotary Encoder
http://www.ebay.it/itm/181881354349?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
N°3 m3x10
N°1 m2x12 with nut
Print the knob
Print the flange
Put this piece of code in arduino micro:
enum PinAssignments {
encoderPinA = 2,
encoderPinB = 3,
clearButton = 8
};
volatile int encoderPos = 0;
int lastReportedPos = 1;
int encoderMove = 0;
boolean A_set = false;
boolean B_set = false;
void setup() {
pinMode(encoderPinA, INPUT);
pinMode(encoderPinB, INPUT);
pinMode(clearButton, INPUT);
digitalWrite(encoderPinA, HIGH); // turn on pullup resistor
digitalWrite(encoderPinB, HIGH); // turn on pullup resistor
digitalWrite(clearButton, HIGH);
// encoder pin on interrupt 0 (pin 2)
attachInterrupt(0, doEncoderA, CHANGE);
// encoder pin on interrupt 1 (pin 3)
attachInterrupt(1, doEncoderB, CHANGE);
// Serial.begin(9600);
}
void loop(){
if (lastReportedPos != encoderPos) {
encoderMove = (encoderPos-lastReportedPos);
//Serial.print("Index:");
//Serial.print(encoderPos, DEC);
//Serial.print("--encoderMove:");
//Serial.print(encoderMove, DEC);
//Serial.println();
if (digitalRead(clearButton) == LOW) {
encoderPos = 0;
}
if ((encoderMove<=127) && (encoderMove>=-127))
Mouse.move(encoderMove, 0, 0);
else
if (encoderMove>127)
Mouse.move(127, 0, 0);
else
Mouse.move(-127, 0, 0);
lastReportedPos = encoderPos;
}
delay(10);
}
// Interrupt on A changing state
void doEncoderA(){
// Test transition
A_set = digitalRead(encoderPinA) == HIGH;
// and adjust counter + if A leads B
encoderPos += (A_set != B_set) ? +1 : -1;
}
// Interrupt on B changing state
void doEncoderB(){
// Test transition
B_set = digitalRead(encoderPinB) == HIGH;
// and adjust counter + if B follows A
encoderPos += (A_set == B_set) ? +1 : -1;
}
At the and you will be able to play Arkanoid with a nice spinner.
Use A arduino pin 2 and B arduino pin 3.
If need more help contact me.
KnobEncoderMouseConBloccoV4.stl | 2.0MB | |
SostSchedaEncoderV2.stl | 1.2MB | |
SpessoreEncoder.stl | 211.7KB |