/*<><><><><><><><>MOUSE ARDUINO KOPPLER<><><><><><><><><> * 10-2010 *<><><><><><><><><><><><><><><><><><><><><><><><><><><><> * * A basic mouse hack example. * Sends data via the Mouse Arduino Koppler to a mouse. * The mouse movement describes different squares. * * * www.dernulleffekt.de *<><><><><><><><><><><><><><><><><><><><><><><><><><><><> * * * * *°·.¸¸.·°·.¸¸.·´·.¸¸.·.¸¸.·´`·.¸¸Wolfgang¸¸Spahn¸¸.··.¸¸¸ */ //variables int gLEDPin = 13; // pinnumber for the controll LED int gHorizontal1 = 3; // 1 pinnumber for horizontal movement int gHorizontal2 = 4; // 2 ... int gVertical1 = 5; // 1 pinnumber for vertikal movement int gVertical2 = 6; // 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 int value = LOW; // previous value of the LED int Counter01 = 0; int gSize = 100; //setup void setup() { pinMode(gLEDPin,OUTPUT); // set led pin as output digitalWrite(gLEDPin,HIGH); // turn on the controll LED 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,LOW); digitalWrite(gHorizontal2,LOW); digitalWrite(gVertical1,LOW); digitalWrite(gVertical2,LOW); } // mainloop void loop() { move(); mousemoveH(); mousemoveV(); } void move(){ Counter01 ++; if (Counter01 < gSize/2) { if (Counter01 < gSize/4) { gStatusHL = HIGH; gStatusHR = LOW; gStatusVL = LOW; gStatusVR = LOW; } else if (Counter01 >= gSize/4) { gStatusHL = LOW; gStatusHR = LOW; gStatusVL = HIGH; gStatusVR = LOW; } } else if (Counter01 >= gSize/2) { if (Counter01 < gSize/4*3) { gStatusHL = LOW; gStatusHR = HIGH; gStatusVL = LOW; gStatusVR = LOW; } else if (Counter01 >= gSize/4*3) { gStatusHL = LOW; gStatusHR = LOW; gStatusVL = LOW; gStatusVR = HIGH; if (Counter01 == gSize) { Counter01 = 0; gSize = random(60, 600); } } } } void mousemoveH() { if (gStatusHL == HIGH) { // 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); delay (1); } if (gStatusHR == HIGH) { // 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); delay (1); } } void mousemoveV() { if (gStatusVL == HIGH) { // 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); delay (1); } if (gStatusVR == HIGH) { // 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); delay (1); } }