Ide:arduino 1.0.4
First, the line connection
S-y--> P5 (A0)
S-x--> P2 (A1)
S-k--> P0
Vcc--> VCC
Gnd--> GND
Second, the Arduino code
//from A0 start,the max is 1023 ,the max Vol is 5V
//A0 ==> P5 //from 470 begin ,less this can‘t working
//A1 ==> P2
//A2 ==> P4 but the value is smaller and can‘t read VCC ,maybe beacause it is used by USB conmunication
//#include "DigiKeyboard.h"
#include "DigiMouse.h"
const int buttonPin = 0;
const int ledPin = 1;
int buttonState = 1;
void setup() {
}
void loop() {
int x = analogRead(A1);
int y = analogRead(A0);
/*DigiKeyboard.sendKeyStroke(0);// prevent missing the first character after a delay:
DigiKeyboard.print("(");
DigiKeyboard.print(x);
DigiKeyboard.print(",");
DigiKeyboard.print(y);
DigiKeyboard.println(")");
DigiKeyboard.delay(1000);*/
DigiMouse.moveY(y-537); //down 10
DigiMouse.delay(100);
DigiMouse.moveX(x-521); //right 20
DigiMouse.delay(100);
//DigiMouse.scroll(5);//pg up
//DigiMouse.delay(500);
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) { //the JoyStick button down is low level
digitalWrite(ledPin, HIGH);
// three buttons are the three LSBs of an unsigned char
DigiMouse.setButtons(1<<0); //1<<0 left click;1<<1 right click
DigiMouse.delay(500);
DigiMouse.setButtons(0); //unclick all
//DigiMouse.delay(500);
}
else {
digitalWrite(ledPin, LOW);
}
}
Description
1, Digimouse.movex (char deltax), Digimouse.movey (char deltay) function is moved relative to the current position;
2, Digimouse.scroll (5); to page up;
3, Digimouse.setbuttons (1<<0) for the left mouse button click, digimouse.setbuttons (1<<1) for the right mouse click, digimouse.setbuttons (0) To clear the Click event.
PS: The Digispark Kickstarter seems to have a little problem, P5 foot, that is, the A0 foot analog can not read the full amount of analog, only from about 470 of the ad value to start reading (maximum ad value is 1023).
Digispark Kickstarter + JoyStick analog Mouse