Arduino-Electronics Interface
Since we received the Arduinos this week I spent time working on code to interface with the modules’ electronic components. We’ll be using the Arduino Joystick library, which works with the Arduino Leonardo.
The Arduino can be made visible as a game controller using the following initialization code:
Our code will dynamically check the ID pins and process the modules’ data pins depending on which module is currently inserted:
For reading from the encoder, we have two options: polling or interrupts. The polling option is less complex but risks skipping transitions if the encoder is turned very quickly. Here is an interrupt service routine that reacts to encoder state changes: The ISR is attached using
attachInterrupt(digitalPinToInterrupt(encoderPinA), encoderISR, CHANGE);
Progress and Next Week’s Deliverables
My progress is on track. Since we’ve now ordered all of our components, I’d like to get my code working with Unity by next week. If the Arduino-Unity integration goes well, I’d like to work on planning the spatial organization of the electronics within the modules.