I appologise before hand for any mistakes in my reporting as I am relatively new to arduino and this forum.
I am having issues trying to compile an example from the menu inside arduino IDE
The code should be identicle to what was loaded from the example menu. But, I have posted it anyways for peace of mind.
Here is the code
/*
JoystickMouseControl
Controls the mouse from a joystick on an Arduino Leonardo, Micro or Due.
Uses a pushbutton to turn on and off mouse control, and a second pushbutton
to click the left mouse button.
Hardware:
- 2-axis joystick connected to pins A0 and A1
- pushbuttons connected to pin D2 and D3
The mouse movement is always relative. This sketch reads two analog inputs
that range from 0 to 1023 (or less on either end) and translates them into
ranges of -6 to 6.
The sketch assumes that the joystick resting values are around the middle of
the range, but that they vary within a threshold.
WARNING: When you use the Mouse.move() command, the Arduino takes over your
mouse! Make sure you have control before you use the command. This sketch
includes a pushbutton to toggle the mouse control state, so you can turn on
and off mouse control.
created 15 Sep 2011
updated 28 Mar 2012
by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/JoystickMouseControl
*/
#include "Mouse.h"
// set pin numbers for switch, joystick axes, and LED:
const int switchPin = 2; // switch to turn on and off mouse control
const int mouseButton = 3; // input pin for the mouse pushButton
const int xAxis = A0; // joystick X axis
const int yAxis = A1; // joystick Y axis
const int ledPin = 5; // Mouse control LED
// parameters for reading the joystick:
int range = 12; // output range of X or Y movement
int responseDelay = 5; // response delay of the mouse, in ms
int threshold = range / 4; // resting threshold
int center = range / 2; // resting position value
bool mouseIsActive = false; // whether or not to control the mouse
int lastSwitchState = LOW; // previous switch state
void setup() {
pinMode(switchPin, INPUT); // the switch pin
pinMode(ledPin, OUTPUT); // the LED pin
// take control of the mouse:
Mouse.begin();
}
void loop() {
// read the switch:
int switchState = digitalRead(switchPin);
// if it's changed and it's high, toggle the mouse state:
if (switchState != lastSwitchState) {
if (switchState == HIGH) {
mouseIsActive = !mouseIsActive;
// turn on LED to indicate mouse state:
digitalWrite(ledPin, mouseIsActive);
}
}
// save switch state for next comparison:
lastSwitchState = switchState;
// read and scale the two axes:
int xReading = readAxis(A0);
int yReading = readAxis(A1);
// if the mouse control state is active, move the mouse:
if (mouseIsActive) {
Mouse.move(xReading, yReading, 0);
}
// read the mouse button and click or not click:
// if the mouse button is pressed:
if (digitalRead(mouseButton) == 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);
}
}
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 thisAxis) {
// read the analog input:
int reading = analogRead(thisAxis);
// map the reading from the analog input range to the output range:
reading = map(reading, 0, 1023, 0, range);
// if the output reading is outside from the rest position threshold, use it:
int distance = reading - center;
if (abs(distance) < threshold) {
distance = 0;
}
// return the distance for this axis:
return distance;
}
Here is the error
In file included from /usr/share/arduino/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino:32:0:
/home/administrator/Arduino/libraries/Mouse/src/Mouse.h:29:2: warning: #warning "Using legacy HID core (non pluggable)" [-Wcpp]
#warning "Using legacy HID core (non pluggable)"
^
/usr/share/arduino/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino: In function ‘void setup()’:
JoystickMouseControl:54:3: error: ‘Mouse’ was not declared in this scope
Mouse.begin();
^
/usr/share/arduino/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino: In function ‘void loop()’:
JoystickMouseControl:77:5: error: ‘Mouse’ was not declared in this scope
Mouse.move(xReading, yReading, 0);
^
JoystickMouseControl:84:10: error: ‘Mouse’ was not declared in this scope
if (!Mouse.isPressed(MOUSE_LEFT)) {
^
JoystickMouseControl:84:26: error: ‘MOUSE_LEFT’ was not declared in this scope
if (!Mouse.isPressed(MOUSE_LEFT)) {
^
JoystickMouseControl:91:9: error: ‘Mouse’ was not declared in this scope
if (Mouse.isPressed(MOUSE_LEFT)) {
^
JoystickMouseControl:91:25: error: ‘MOUSE_LEFT’ was not declared in this scope
if (Mouse.isPressed(MOUSE_LEFT)) {
^
exit status 1
‘Mouse’ was not declared in this scope
I have installed a new system but I am unable to access it in person so I am sshing to the device that the arduino is connected to.
I am confused because I definetely saw Mouse being imported at the beginning. So, I am unsure as to why it is not able to compile.
The remote server is running a Lubuntu installation. It is not possible to have windows.(We need to figure out iPXE before we can make it work.)
The arduino processor is ATmega 32U4 and I believe the model is a Leonardo.
I have verified that both mouse and keyboard have been installed via the Library Manager under Tools.
Is there something simple I have missed out or troubleshooting steps I need to further do?