首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VSCode中的PlatformIO

VSCode中的PlatformIO
EN

Stack Overflow用户
提问于 2019-05-25 05:32:02
回答 1查看 405关注 0票数 0

我用PlatformIO下载了VS代码的最新版本,我也从PlatformIO库管理器下载了Mouse.h库,即使这样,在我上传代码到我的Micro Pro后,鼠标对操纵杆没有反应!但是当我通过Arduino IDE上传时,同样的代码也可以工作!

我比较了.platformio/lib中的Mouse.h和程序文件\Arduino\libraries中的Mouse.h。我比较了.platformio/lib中的Mouse.cpp和程序文件\Arduino\libraries中的Mouse.cpp

它们有完全相同的代码!

这是我的MICRO 32u4 5v的代码:

代码语言:javascript
复制
/* HID Joystick Mouse Example
   by: Jim Lindblom
   date: 1/12/2012
   license: MIT License - Feel free to use this code for any purpose.
   No restrictions. Just keep this license if you go on to use this
   code in your future endeavors! Reuse and share.

   This is very simplistic code that allows you to turn the
   SparkFun Thumb Joystick (http://www.sparkfun.com/products/9032)
   into an HID Mouse. The select button on the joystick is set up
   as the mouse left click.
 */

#include <Arduino.h>
#include <Mouse.h>
int horzPin = A0;  // Analog output of horizontal joystick pin
int vertPin = A1;  // Analog output of vertical joystick pin
int selPin = 9;  // select button pin of joystick

int vertZero, horzZero;  // Stores the initial value of each axis, usually around 512
int vertValue, horzValue;  // Stores current analog output of each axis
const int sensitivity = 200;  // Higher sensitivity value = slower mouse, should be <= about 500
int mouseClickFlag = 0;

void setup()
{
  pinMode(horzPin, INPUT);  // Set both analog pins as inputs
  pinMode(vertPin, INPUT);
  pinMode(selPin, INPUT);  // set button select pin as input
  digitalWrite(selPin, HIGH);  // Pull button select pin high
  delay(1000);  // short delay to let outputs settle
  vertZero = analogRead(vertPin);  // get the initial values
  horzZero = analogRead(horzPin);  // Joystick should be in neutral position when reading these
}

void loop()
{
  vertValue = analogRead(vertPin) - vertZero;  // read vertical offset
  horzValue = analogRead(horzPin) - horzZero;  // read horizontal offset
//delay(3000);

  if (vertValue != 0)
    Mouse.move(0, vertValue/sensitivity, 0);  // move mouse on y axis
  if (horzValue != 0)
    Mouse.move((horzValue/sensitivity) *-1, 0, 0);  // move mouse on x axis

  if ((digitalRead(selPin) == 0) && (!mouseClickFlag))  // if the joystick button is pressed
  {
    mouseClickFlag = 1;
    Mouse.press(MOUSE_LEFT);  // click the left button down
  }
  else if ((digitalRead(selPin))&&(mouseClickFlag)) // if the joystick button is not pressed
  {
    mouseClickFlag = 0;
    Mouse.release(MOUSE_LEFT);  // release the left button
  }
}
EN

回答 1

Stack Overflow用户

发布于 2020-02-09 22:59:55

在安装lib后,您是否重新启动了VS Code?

对我来说,它在某些情况下解决了这类问题。

编辑:您是否通过按"Ctrl + shift + p“来”重建IntelliSense索引“?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56299741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档