0

Arduinoの勉強を始めたばかりのものです。

「Arduinoをはじめよう 第3版」P.67のLeonardo mouseを作るためにArduino IDEのサンプル「ButtonMouseControl」を入力しましたがうまくいきません。
以下のようなエラーが出てきます。

「「Mouse.h」に対して複数のライブラリが見つかりました
使用済:C:\Users\ユーザー\OneDrive\ドキュメント\Arduino\libraries\Mouse
未使用:C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries\Mouse
exit status 1
「Mouse」が存在しません。スケッチに「#include < Mouse.h>」という行を含めていますか?」

『スケッチに「#include < Mouse.h>」という行を含めていますか?」』
とありますが、スケッチの1行目に記述しております。
また、「使用済:~」のフォルダを削除して検証してみましたが結果は変わりませんでした。

どなたかご教示いただけないでしょうか。
以上、何とぞよろしくお願いいたします。

以下コードです。

#include <Mouse.h>

// set pin numbers for the five buttons:
const int upButton = 2;
const int downButton = 3;
const int leftButton = 4;
const int rightButton = 5;
const int mouseButton = 6;

int range = 5;              // output range of X or Y movement; affects movement speed
int responseDelay = 10;     // response delay of the mouse, in ms


void setup() {
  // initialize the buttons' inputs:
  pinMode(upButton, INPUT);
  pinMode(downButton, INPUT);
  pinMode(leftButton, INPUT);
  pinMode(rightButton, INPUT);
  pinMode(mouseButton, INPUT);
  // initialize mouse control:
  Mouse.begin();
}

void loop() {
  // read the buttons:
  int upState = digitalRead(upButton);
  int downState = digitalRead(downButton);
  int rightState = digitalRead(rightButton);
  int leftState = digitalRead(leftButton);
  int clickState = digitalRead(mouseButton);

  // calculate the movement distance based on the button states:
  int  xDistance = (leftState - rightState) * range;
  int  yDistance = (upState - downState) * range;

  // if X or Y is non-zero, move:
  if ((xDistance != 0) || (yDistance != 0)) {
    Mouse.move(xDistance, yDistance, 0);
  }

  // if the mouse button is pressed:
  if (clickState == HIGH) {
    // if the mouse is not pressed, press it:
    if (!Mouse.isPressed(MOUSE_LEFT)) {
      Mouse.press(MOUSE_LEFT);
    }
  }
  // else the mouse button is not pressed:
  else {
    // if the mouse is pressed, release it:
    if (Mouse.isPressed(MOUSE_LEFT)) {
      Mouse.release(MOUSE_LEFT);
    }
  }

  // a delay so the mouse doesn't move too fast:
  delay(responseDelay);
}
2

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。