Monday, October 27, 2008

Introducing the InputShield

The InputShield is a shield for the Arduino that gives it a joystick and two buttons (A and B). That means I can connect it on top of the Arduino, and read in the X and Y coordinates over the analog input pins. I can also read the values of buttons 1 and 2 with digital read functions, so it's pretty straightforward to code too (code at the bottom).


I glued a small vibrator motor to the back of the board too, so it can be used to give a little bit of "force feedback" :-) I don't have a clean shot of the back yet, but here are some up-close pictures. You can see the double-stacked right angle female pin header on the top of the board, which I put so I can still fit solid core wires in and access power, ground, and the other digital pins (for when I wire up an accelerometer):




The InputShield comes with PCB traces for different types of layouts (partly because Chris is a lefty and I'm a righty). That way, when it's a kit, I can solder the joystick or buttons in one configuration or the other:

My friend showed me how to take 3D perspective shots like he used to, so believe it or not... I actually took this photo! (no, seriously... although I didn't set up the lighting or the camera settings - I don't even know what camera settings mean or do):



I spent almost all weekend soldering a few of these up, and then taking photos with the camera (they're all on Flickr), and I also wrote some small code to read the values using the Arduino:


void setup()
{
Serial.begin(9600);
pinMode(7,OUTPUT);
digitalWrite(7,LOW);

pinMode(11,OUTPUT);
digitalWrite(11,HIGH);

digitalWrite(4, HIGH); pinMode(4, INPUT);
digitalWrite(5, HIGH); pinMode(5, INPUT);
digitalWrite(6, HIGH); pinMode(6, INPUT);

digitalWrite(8, HIGH); pinMode(8, INPUT);
digitalWrite(9, HIGH); pinMode(9, INPUT);
digitalWrite(10, HIGH); pinMode(10, INPUT);
}


void loop()
{
Serial.print(" L1: ");
Serial.print((unsigned int)analogRead(5));
Serial.print(" V1: ");
Serial.print((unsigned int)analogRead(4));
Serial.print(" L2: ");
Serial.print((unsigned int)analogRead(3));
Serial.print(" V2: ");
Serial.print((unsigned int)analogRead(2));

Serial.print(" B1: ");
Serial.print((unsigned int)digitalRead(4));
Serial.print(" B2: ");
Serial.print((unsigned int)digitalRead(5));
Serial.print(" B3: ");
Serial.print((unsigned int)digitalRead(6));

Serial.print(" B5: ");
Serial.print((unsigned int)digitalRead(8));
Serial.print(" B6: ");
Serial.print((unsigned int)digitalRead(9));
Serial.print(" B7: ");
Serial.print((unsigned int)digitalRead(10));

Serial.print("\n");
digitalWrite(7,LOW);
delay(200);
digitalWrite(7,HIGH);
delay(200);
}

I'll put the InputShield up on the store over at Liquidware... and I'll also upload a couple of videos of the other stuff I made with it.

No comments: