/*<><><><><><><><>MOUSE SHIELD<><><><><><><><> * Wolfgang Spahn 7-2009 *<><><><><><><><><><><><><><><><><><><><><><> * * A basic mouse shield example. Reads 2 analog * inputs and 2 digital inputs. Sends data to * the mouse shield. * * * www.wolfgang-spahn.de */ //Send a single impluse to the MouseWarrior //if the inputvalue is +1 move the Mouse to the right, //if the inputvalue is negative move the Mouse to the left //variables int gLEDPin = 13; // pinnumber for the controll LED int gButtonHL = 7; // pinnumber for the inputbutton horizontal left int gButtonHR = 8; // pinnumber for the inputbutton horizontal right int gButtonVL = 9; // pinnumber for the inputbutton vertical left int gButtonVR = 10; // pinnumber for the inputbutton vertical right int gHorizontal1 = 2; // 1 pinnumber for horizontal movement int gHorizontal2 = 3; // 2 ... int gVertical1 = 4; // 1 pinnumber for vertikal movement int gVertical2 = 5; // 2 ... int gStatusHL = LOW; // status of the input horizontal 1 int gStatusHR = LOW; // status of the input horizontal 2 int gStatusVL = LOW; // status of the input vertical 1 int gStatusVR = LOW; // status of the input vertical 2 //setup void setup() { pinMode(gLEDPin,OUTPUT); // set led pin as output digitalWrite(gLEDPin,HIGH); // turn on the controll LED pinMode(gButtonHL,INPUT); // set pin for horizontal button HL as input pinMode(gButtonHR,INPUT); // set pin for horizontal button HR as input pinMode(gButtonVL,INPUT); // set pin for vertical button VL as input pinMode(gButtonVR,INPUT); // set pin for vertical button VR as input pinMode(gHorizontal1,OUTPUT); // set pin for horizontal movement 1 as output pinMode(gHorizontal2,OUTPUT); // set pin for horizontal movement 2 as output pinMode(gVertical1,OUTPUT); // set pin for vertical movement 1 as output pinMode(gVertical2,OUTPUT); // set pin for vertical movement 2 as output digitalWrite(gHorizontal1,HIGH); digitalWrite(gHorizontal1,HIGH); digitalWrite(gVertical1,HIGH); digitalWrite(gVertical2,HIGH); } // mainloop void loop() { readoutH(); mousemoveH(); readoutV(); mousemoveV(); } void readoutH() { gStatusHL = digitalRead(gButtonHL); // readout button for horizontal 1 input gStatusHR = digitalRead(gButtonHR); // readout button for horizontal 2 input } void mousemoveH() { if (gStatusHL == LOW) { // horizontal move left digitalWrite(gHorizontal1,LOW); // set pin 1 for horizontal move low delay(1); // delay digitalWrite (gHorizontal2,LOW); // set pin 2 for horizontal move low delay (1); digitalWrite(gHorizontal1,HIGH); // set them high again digitalWrite(gHorizontal2,HIGH); } if (gStatusHR == LOW) { // horizontal move left digitalWrite(gHorizontal2,LOW); // set pin 2 for horizontal move low delay(1); // delay digitalWrite (gHorizontal1,LOW); // set pin 1 for horizontal move low delay (1); digitalWrite(gHorizontal2,HIGH); // set them high again digitalWrite(gHorizontal1,HIGH); } } void readoutV(){ gStatusVL = digitalRead(gButtonVL); // readout button for vertical 1 input gStatusVR = digitalRead(gButtonVR); // readout button for vertical 2 input } void mousemoveV() { if (gStatusVL == LOW) { // vertical move left digitalWrite(gVertical1,LOW); // set pin 1 for vertical move low delay(1); // delay digitalWrite (gVertical2,LOW); // set pin 2 for vertical move low delay (1); digitalWrite(gVertical1,HIGH); // set them high again digitalWrite(gVertical2,HIGH); } if (gStatusVR == LOW) { // vertical move left digitalWrite(gVertical2,LOW); // set pin 2 for vertical move low delay(1); // delay digitalWrite (gVertical1,LOW); // set pin 1 for vertical move low delay (1); digitalWrite(gVertical2,HIGH); // set them high again digitalWrite(gVertical1,HIGH); } }