Digispark Kickstarter + JoyStick analog Mouse

Source: Internet
Author: User



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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.