با استفاده از کتابخانه ماوس، میتوانید مکاننمای روی صفحه رایانه را با Arduino Leonardo، Micro یا Due کنترل کنید. این مثال خاص از یک دکمه فشاری برای روشن و خاموش کردن کنترل ماوس با جوی استیک استفاده می کند.
حرکت مکان نما از آردوینو همیشه نسبی است. بنابراین هر بار که ورودی آنالوگ خوانده می شود، موقعیت مکان نما نسبت به موقعیت فعلی آن به روز می شود.
دو ورودی آنالوگ از 0 تا 1023 به محدوده های 12- تا 12 ترجمه می شوند. این طرح فرض می کند که مقادیر استراحت جوی استیک در حدود وسط محدوده هستند، اما در یک آستانه تغییر می کنند.
دکمه فشاری به شما امکان می دهد کنترل ماوس را روشن و خاموش کنید. هنگامی که آردوینو در حال کنترل ماوس است، یک LED وضعیت متصل به پین 5 روشن می شود.
نرم افزار مورد نیاز
- هیچ یک
تصویر با استفاده از Fritzing ایجاد شده است . برای نمونه مدارهای بیشتر، صفحه پروژه فریتزینگ را ببینید
شماتیک:
کد
/* JoystickMouseControl Controls the mouse from a joystick on an Arduino Leonardo or Micro. 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 Sept 2011 updated 28 Mar 2012 by Tom Igoe this code is in the public domain */
سخت افزار مورد نیاز
برای جزئیات بیشتر: کد کنترل ماوس جوی استیک آردوینو