chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何用Arduino Uno和游戲桿制作PC鼠標(biāo)

454398 ? 來源:網(wǎng)絡(luò)整理 ? 作者:佚名 ? 2019-11-05 17:01 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

第1步:材料

這個(gè)項(xiàng)目不需要很多材料:

1 Arduino Uno

5對(duì)公對(duì)母線

5對(duì)母對(duì)母線(連接到操縱桿模塊并添加操縱桿的延伸長(zhǎng)度。

1個(gè)操縱桿(我使用了SainSmart PS2游戲桿模塊,并且會(huì)推薦它)

步驟2:設(shè)置Arduino Uno

Uno的設(shè)置可以在材料圖片,以及這里的說明:

將五根母頭線連接到操縱桿模塊的引腳上。現(xiàn)在,將五根公頭線連接到母線的末端并將它們連接到這樣的Arduino:

1.操縱桿上的地面到Arduino Gnd

2.操縱桿上的+ 5V到Arduino 5V

3。操縱桿上的UPx到Arduino上的A0

4.操縱桿上的UPy到A1

5. SW引腳(數(shù)字式點(diǎn)擊開關(guān))到數(shù)字引腳7上Arduino

第3步:上傳Joysti ck程序到Arduino

將Uno連接到你的PC并上傳這里看到的操縱桿代碼(請(qǐng)注意我最初沒有創(chuàng)建這個(gè)代碼):

int pushPin = 7; // potentiometer wiper (middle terminal) connected to analog pin 3

int xPin = 0;

int yPin = 1;

int xMove = 0;

int yMove = 0;

// outside leads to ground and +5V

int valPush = HIGH; // variable to store the value read

int valX = 0;

int valY = 0;

void setup()

{

pinMode(pushPin,INPUT);

Serial.begin(9600); // setup serial

digitalWrite(pushPin,HIGH);

}

void loop()

{

valX = analogRead(xPin); // read the x input pin

valY = analogRead(yPin); // read the y input pin

valPush = digitalRead(pushPin); // read the push button input pin

Serial.println(String(valX) + “ ” + String(valY) + “ ” + valPush); //output to Java program

}

步驟4:設(shè)置Java程序

現(xiàn)在已經(jīng)設(shè)置了Uno,我們需要將它連接到我的Java程序,該程序能夠獲取Uno的串行輸出值特殊庫RxTx并使用庫集合JNA移動(dòng)鼠標(biāo)。這兩個(gè)庫都包含在此步驟結(jié)束時(shí)供下載。請(qǐng)注意,我從示例RxTx中更改的代碼的唯一部分是添加了以我為操縱桿校準(zhǔn)的方式移動(dòng)鼠標(biāo)的方法。它有點(diǎn)粗糙,但它符合我的目的。

我使用BlueJ作為我的IDE,但無論你使用哪種Java IDE,都要為這個(gè)項(xiàng)目安裝RxTx和JNA庫,我將其命名為“Mouse”。完成后,創(chuàng)建一個(gè)項(xiàng)目并包含以下代碼:

import java.awt.*;

import java.awt.event.InputEvent;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.OutputStream;

import gnu.io.CommPortIdentifier;

import gnu.io.SerialPort;

import gnu.io.SerialPortEvent;

import gnu.io.SerialPortEventListener;

import java.util.Enumeration;

public class Mouse implements SerialPortEventListener {

SerialPort serialPort;

/** The port we‘re normally going to use. */

private static final String PORT_NAMES[] = {

“/dev/tty.usbserial-A9007UX1”, // Mac OS X

“/dev/ttyACM0”, // Raspberry Pi

“/dev/ttyUSB0”, // Linux

“COM4”, // Windows**********(I changed)

};

/**

* A BufferedReader which will be fed by a InputStreamReader

* converting the bytes into characters

* making the displayed results codepage independent

*/

private BufferedReader input;

/** The output stream to the port */

private OutputStream output;

/** Milliseconds to block while waiting for port open */

private static final int TIME_OUT = 2000;

/** Default bits per second for COM port. */

private static final int DATA_RATE = 9600;

int buttonOld = 1;

public void initialize() {

// the next line is for Raspberry Pi and

// gets us into the while loop and was suggested here was suggested http://www.raspberrypi.org/phpBB3/viewtopic.php?f.。.

//System.setProperty(“gnu.io.rxtx.SerialPorts”, “/dev/ttyACM0”); I got rid of this

CommPortIdentifier portId = null;

Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();

//First, Find an instance of serial port as set in PORT_NAMES.

while (portEnum.hasMoreElements()) {

CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();

for (String portName : PORT_NAMES) {

if (currPortId.getName().equals(portName)) {

portId = currPortId;

break;

}

}

}

if (portId == null) {

System.out.println(“Could not find COM port.”);

return;

}

try {

// open serial port, and use class name for the appName.

serialPort = (SerialPort) portId.open(this.getClass().getName(),

TIME_OUT);

// set port parameters

serialPort.setSerialPortParams(DATA_RATE,

SerialPort.DATABITS_8,

SerialPort.STOPBITS_1,

SerialPort.PARITY_NONE);

// open the streams

input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));

output = serialPort.getOutputStream();

// add event listeners

serialPort.addEventListener(this);

serialPort.notifyOnDataAvailable(true);

} catch (Exception e) {

System.err.println(e.toString());

}

}

/**

* This should be called when you stop using the port.

* This will prevent port locking on platforms like Linux.

*/

public synchronized void close() {

if (serialPort != null) {

serialPort.removeEventListener();

serialPort.close();

}

}

/**

* Handle an event on the serial port. Read the data and print it. In this case, it calls the mouseMove method.

*/

public synchronized void serialEvent(SerialPortEvent oEvent) {

if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {

try {

String inputLine=input.readLine();

mouseMove(inputLine);

System.out.println(“********************”);

//System.out.println(inputLine);

} catch (Exception e) {

System.err.println(e.toString());

}

}

// Ignore all the other eventTypes, but you should consider the other ones.

}

public static void main(String[] args) throws Exception {

Mouse main = new Mouse();

main.initialize();

Thread t=new Thread() {

public void run() {

//the following line will keep this app alive for 1000 seconds,

//waiting for events to occur and responding to them (printing incoming messages to console)。

try {Thread.sleep(1000000);} catch (InterruptedException ie) {}

}

};

t.start();

System.out.println(“Started”);

}

// My method mouseMove, takes in a string containing the three data points and operates the mouse in turn

public void mouseMove(String data) throws AWTException

{

int index1 = data.indexOf(“ ”, 0);

int index2 = data.indexOf(“ ”, index1+1);

int yCord = Integer.valueOf(data.substring(0, index1));

int xCord = Integer.valueOf(data.substring(index1 + 1 , index2));

int button = Integer.valueOf(data.substring(index2 + 1));

Robot robot = new Robot();

int mouseY = MouseInfo.getPointerInfo().getLocation().y;

int mouseX = MouseInfo.getPointerInfo().getLocation().x;

if (button == 0)

{

if (buttonOld == 1)

{

robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);

robot.delay(10);

}

}

else

{

if (buttonOld == 0)

robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

}

if (Math.abs(xCord - 500) 》 5)

mouseX = mouseX + (int)((500 - xCord) * 0.02);

if (Math.abs(yCord - 500) 》 5)

mouseY = mouseY - (int)((500 - yCord) * 0.02);

robot.mouseMove(mouseX, mouseY);

buttonOld = button;

System.out.println(xCord + “:” + yCord + “:” + button + “:” + mouseX + “:” + mouseY);

return;

}

}

步驟5:疑難解答

使Java程序正常工作可能是難。如果您遇到困難我會(huì)得到一些提示:

- 將PORT_NAMES []中的“Com4”字符串更改為您的arduino Uno所連接的端口。 (我從Java程序中的默認(rèn)Com3更改為Com4)

- 指出與Raspberry Pi相關(guān)的行(如果你復(fù)制了我的程序,我已經(jīng)這樣做了)

- 單擊“重建軟件包”或等效的IDE

-在IDE中重置Java虛擬機(jī)。甚至可能在第一次使用鼠標(biāo)之前重置程序。

第6步:結(jié)論

我希望這個(gè)項(xiàng)目適用于您,并且您可以改善它。最終,最簡(jiǎn)單的解決方案是使用Arduino Leonard或Mini作為鼠標(biāo)輸入的系統(tǒng)設(shè)備,但我發(fā)現(xiàn)使Uno功能以非設(shè)計(jì)的方式 - 鼠標(biāo) - 通過使用我的方式很有趣有限的Java知識(shí)。

我獨(dú)自學(xué)習(xí)了很多方法,并希望將來增加一些功能:

-右鍵單擊按鈕。操縱桿有一個(gè)我保留左鍵的按鈕。

- 這個(gè)項(xiàng)目的實(shí)際設(shè)備驅(qū)動(dòng)程序。我不確定這是否可行,也許有人可以就此問題給我啟發(fā)!

責(zé)任編輯:wv

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 鼠標(biāo)
    +關(guān)注

    關(guān)注

    6

    文章

    597

    瀏覽量

    41671
  • Arduino
    +關(guān)注

    關(guān)注

    190

    文章

    6526

    瀏覽量

    196787
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    PAW3395DM-T6QU:光學(xué)游戲導(dǎo)航芯片手冊(cè)

    本資料為市場(chǎng)上普遍用于游戲鼠標(biāo)的傳感器,該傳感器可支持8k鼠標(biāo)
    發(fā)表于 02-06 14:57 ?2次下載

    UNO Q:開啟Arduino的全新未來

    圖源: * Arduino* 作者:Matt Campbell,貿(mào)澤電子專稿 發(fā)布日期: 2025年10月7日 Arduino UNO Q不僅是靈活UNO平臺(tái)的下一代產(chǎn)品,更是一種全新
    的頭像 發(fā)表于 12-15 11:46 ?753次閱讀

    貿(mào)澤電子開售全新Arduino UNO Q單板計(jì)算機(jī)

    貿(mào)澤電子開售全新Arduino UNO Q單板計(jì)算機(jī)。Arduino UNO Q單板計(jì)算機(jī)(SBC)將高性能計(jì)算與實(shí)時(shí)控制結(jié)合,提供理想的創(chuàng)新平臺(tái)。
    的頭像 發(fā)表于 11-08 09:50 ?1317次閱讀

    何用FPGA實(shí)現(xiàn)4K視頻的輸入輸出與處理

    游戲、影視和顯示領(lǐng)域,4K 已經(jīng)成為標(biāo)配。而今天,我們就來聊聊——如何用 FPGA 實(shí)現(xiàn) 4K 視頻的輸入輸出與處理。
    的頭像 發(fā)表于 10-15 10:47 ?2085次閱讀
    如<b class='flag-5'>何用</b>FPGA實(shí)現(xiàn)4K視頻的輸入輸出與處理

    Arduino Uno l兩輪自平衡機(jī)器人 電機(jī)驅(qū)動(dòng)無輸出求解

    Arduino Uno l兩輪自平衡機(jī)器人 電機(jī)驅(qū)動(dòng)無輸出求解
    發(fā)表于 10-15 06:36

    Arduino UNO Q 登陸 DigiKey,現(xiàn)已開放預(yù)訂

    融合高性能微處理器與專用微控制器,Arduino UNO Q加強(qiáng)創(chuàng)新開發(fā)能力 美國, 明尼蘇達(dá), 錫夫里弗福爾斯市 - 2025 年 10 月 07 日 全球領(lǐng)先的電子元器件與自動(dòng)化產(chǎn)品分銷商
    的頭像 發(fā)表于 10-13 14:55 ?576次閱讀
    <b class='flag-5'>Arduino</b> <b class='flag-5'>UNO</b> Q 登陸 DigiKey,現(xiàn)已開放預(yù)訂

    高通宣布收購 Arduino,加速普及前沿邊緣計(jì)算與 AI 技術(shù)

    “ ?全新 Arduino UNO Q 開發(fā)板與 Arduino App Lab 將為數(shù)百萬開發(fā)者帶來高通 Dragonwing 處理器的強(qiáng)大動(dòng)力。? ” ? 要點(diǎn)速覽: 強(qiáng)強(qiáng)聯(lián)合 :此次收購將高
    的頭像 發(fā)表于 10-08 11:15 ?676次閱讀
    高通宣布收購 <b class='flag-5'>Arduino</b>,加速普及前沿邊緣計(jì)算與 AI 技術(shù)

    如何在 NuMaker-IoT-M467 板上使用 Arduino IDE 控制 Wi-Fi 模塊?

    在NuMaker開發(fā)板上,有一個(gè)ESP-12F Wi-Fi模塊;但是,Arduino IDE 中的 NuMaker UNO 包不提供該模塊的相關(guān)控制。如果您希望在 Arduino IDE 中控制此模塊,您應(yīng)該如何進(jìn)行?
    發(fā)表于 09-04 08:28

    何用Arduino Nano/UNO R3開發(fā)板給另一個(gè)Arduino IDE不能下載的Arduino Nano/UNO R3開發(fā)板重新燒錄引導(dǎo)程序bootlaoder

    本文介紹了如何用能夠Arduino IDE下載的Arduino Nano/UNO R3開發(fā)板給另一個(gè)Arduino IDE不能下載的
    的頭像 發(fā)表于 08-08 20:16 ?3532次閱讀
    如<b class='flag-5'>何用</b><b class='flag-5'>Arduino</b> Nano/<b class='flag-5'>UNO</b> R3開發(fā)板給另一個(gè)<b class='flag-5'>Arduino</b> IDE不能下載的<b class='flag-5'>Arduino</b> Nano/<b class='flag-5'>UNO</b> R3開發(fā)板重新燒錄引導(dǎo)程序bootlaoder

    外星人無線充電鼠標(biāo)墊支持qi協(xié)議么?

    外星人無線充電鼠標(biāo)墊采用Qi協(xié)議,支持無線充電,兼具美觀與實(shí)用性,適用于辦公與游戲場(chǎng)景。
    的頭像 發(fā)表于 07-27 08:36 ?872次閱讀
    外星人無線充電<b class='flag-5'>鼠標(biāo)</b>墊支持qi協(xié)議么?

    顛覆游戲體驗(yàn)!全球首款UWB無線鼠標(biāo)面世

    當(dāng)延遲壓縮至200微秒,當(dāng)輪詢率飆升至8000Hz,當(dāng)信號(hào)在擁擠頻段中無阻穿梭——Waizowl Cloud Ultra游戲鼠標(biāo)用UWB技術(shù)撕開了無線外設(shè)的性能天花板。
    的頭像 發(fā)表于 07-18 10:33 ?1762次閱讀
    顛覆<b class='flag-5'>游戲</b>體驗(yàn)!全球首款UWB無線<b class='flag-5'>鼠標(biāo)</b>面世

    【VisionFive 2單板計(jì)算機(jī)試用體驗(yàn)】2、打造復(fù)古游戲機(jī)(Batocera鏡像+FBNeo虛擬機(jī), 多款游戲ROM分享)

    衷心感謝電子發(fā)燒友論壇! 1、基本知識(shí) 制作一個(gè)游戲機(jī)系統(tǒng),需要3個(gè)關(guān)鍵步驟: Linux游戲系統(tǒng)發(fā)行版 游戲模擬器 游戲ROM 下面分別介
    發(fā)表于 07-17 21:58

    基于stm32和mpu9250的usb hid鍵盤、鼠標(biāo)、游戲控制器實(shí)例打包下載

    基于stm32和mpu9250的usb hid鍵盤、鼠標(biāo)、游戲控制器實(shí)例打包,推薦下載!
    發(fā)表于 05-29 21:44

    基于stm32和mpu9250的usb hid鍵盤、鼠標(biāo)游戲控制器

    基于stm32和mpu9250的usb hid鍵盤、鼠標(biāo)、游戲控制器 項(xiàng)目實(shí)例下載! 純分享帖,需要者可點(diǎn)擊附件免費(fèi)獲取完整資料~~~【免責(zé)聲明】本文系網(wǎng)絡(luò)轉(zhuǎn)載,版權(quán)歸原作者所有。本文所用視頻、圖片、文字如涉及作品版權(quán)問題,請(qǐng)第一時(shí)間告知,刪除內(nèi)容!
    發(fā)表于 05-23 20:53

    客廳變游戲室?如何用樹莓派實(shí)現(xiàn) Moonlight 游戲流媒體

    在這個(gè)項(xiàng)目中,我們將向您展示如何使用Moonlight將游戲直接流式傳輸?shù)侥腞aspberryPi。Moonlight:https://moonlight-stream.org/Moonlight
    的頭像 發(fā)表于 03-25 09:37 ?1628次閱讀
    客廳變<b class='flag-5'>游戲</b>室?如<b class='flag-5'>何用</b>樹莓派實(shí)現(xiàn) Moonlight <b class='flag-5'>游戲</b>流媒體