Mouse.move()
설명
연결된 컴퓨터에서 커서를 움직인다. 화면에서의 모션은 늘 커서의 현재 위치에 상대적이다. Mouse.move() 을 쓰기 전에 Mouse.begin() 을 부르시오.
문법
Mouse.move(xVal, yVal, wheel);
매개변수
- xVal: x-축을 따라 움직이는 양 - signed char
- yVal: y-축을 따라 움직이는 양 - signed char
- wheel: 스크롤 휠 움직이는 양 - signed char
반환값
- 없음
예제 코드
#include <Mouse.h>
const int xAxis = A1; //analog sensor for X axis
const int yAxis = A2; // analog sensor for Y axis
int range = 12; // output range of X or Y movement
int responseDelay = 2; // response delay of the mouse, in ms
int threshold = range / 4; // resting threshold
int center = range / 2; // resting position value
int minima[] = {1023, 1023}; // actual analogRead minima for {x, y}
int maxima[] = {0, 0}; // actual analogRead maxima for {x, y}
int axis[] = {xAxis, yAxis}; // pin numbers for {x, y}
int mouseReading[2]; // final mouse readings for {x, y}
void setup() {
Mouse.begin();
}
void loop() {
// read and scale the two axes:
int xReading = readAxis(0);
int yReading = readAxis(1);
// move the mouse:
Mouse.move(xReading, yReading, 0);
delay(responseDelay);
}
/*
reads an axis (0 or 1 for x or y) and scales the
analog input range to a range from 0 to <range>
*/
int readAxis(int axisNumber) {
int distance = 0; // distance from center of the output range
// read the analog input:
int reading = analogRead(axis[axisNumber]);
// of the current reading exceeds the max or min for this axis,
// reset the max or min:
if (reading < minima[axisNumber]) {
minima[axisNumber] = reading;
}
if (reading > maxima[axisNumber]) {
maxima[axisNumber] = reading;
}
// map the reading from the analog input range to the output range:
reading = map(reading, minima[axisNumber], maxima[axisNumber], 0, range);
// if the output reading is outside from the
// rest position threshold, use it:
if (abs(reading - center) > threshold) {
distance = (reading - center);
}
// the Y axis needs to be inverted in order to
// map the movemment correctly:
if (axisNumber == 1) {
distance = -distance;
}
// return the distance for this axis:
return distance;
}
※ 주의 및 경고:
Mouse.move() 명령을 쓸 때, 아두이노가 마우스를 차지한다! 명령을 사용하기 전에 제어권이 있는지 확인하십시오. 마우스 컨트롤 상태를 토글하는 푸시 버튼이 효과적이다.
더보기
- 언어 : Arduino - Mouse
- 언어 : Mouse.begin()
- 언어 : Mouse.click()
- 언어 : Mouse.end()
- 언어 : Mouse.isPressed()
- 언어 : Mouse.press()
- 언어 : Mouse.release()
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables.
Additionally, some links direct to products from our own brand, DIYables.