当前位置: 首页 > news >正文

双轴按键摇杆模块、电位器,使用详解

双轴按键摇杆模块

在 Arduino 中使用摇杆模块时,其实并没有专门针对摇杆模块的特定官方库,因为摇杆模块本质上就是电位器(模拟输入)和按键(数字输入)的组合,你可以直接使用 Arduino 自带的基础函数来读取摇杆数据。

在这里插入图片描述

// 定义摇杆引脚
const int xPin = A0;
const int yPin = A1;
const int buttonPin = 2;void setup() {// 初始化串口通信Serial.begin(9600);// 将按键引脚设置为输入模式pinMode(buttonPin, INPUT_PULLUP);
}void loop() {// 读取X轴和Y轴的模拟值int xValue = analogRead(xPin);int yValue = analogRead(yPin);// 读取按键状态int buttonState = digitalRead(buttonPin);// 输出读取到的值Serial.print("X: ");Serial.print(xValue);Serial.print("  Y: ");Serial.print(yValue);Serial.print("  Button: ");Serial.println(buttonState);delay(100);
}

电位器

在这里插入图片描述

电位器,滑动变阻器,旋转旋钮改变输出阻值,故可以直接串联、并联进电路,改变电路阻值。

在这里插入图片描述

通过模拟电路调节LED亮度

在这里插入图片描述

const int potentiometerPin = A0;
const int ledPin = 3;int sensorValue = 0;      
int outputValue = 0;    void setup() {Serial.begin(9600);pinMode(ledPin, OUTPUT);
}void loop() {sensorValue = analogRead(potentiometerPin);outputValue = map(sensorValue, 0, 1023, 0, 255);  Serial.print("电位器值 = ");Serial.print(sensorValue);Serial.print("\t LED输出 = ");Serial.println(outputValue);analogWrite(ledPin, outputValue); delay(10);
}

文章转载自:

http://QLzZemHK.mstrb.cn
http://ePTzeW7l.mstrb.cn
http://v00TDsC1.mstrb.cn
http://GEtnMHI4.mstrb.cn
http://FPiA40Uv.mstrb.cn
http://MokbG7Jo.mstrb.cn
http://TaGPmtAQ.mstrb.cn
http://H5WZ0LWI.mstrb.cn
http://oGPCo0Bc.mstrb.cn
http://fmsMHYxH.mstrb.cn
http://VqGRUZyQ.mstrb.cn
http://oIcIvamP.mstrb.cn
http://yax0R9yG.mstrb.cn
http://XbDTjXf4.mstrb.cn
http://4JrEauap.mstrb.cn
http://fHSPRqCb.mstrb.cn
http://3tSdjiZn.mstrb.cn
http://N8rT0TSN.mstrb.cn
http://qqZXGJa7.mstrb.cn
http://FGNB4Wyj.mstrb.cn
http://tRgVwZiD.mstrb.cn
http://1Zc1umxU.mstrb.cn
http://ALJZRE7p.mstrb.cn
http://hCb9YxRG.mstrb.cn
http://LtK3PIBx.mstrb.cn
http://U3dvqicM.mstrb.cn
http://4E8CckxZ.mstrb.cn
http://nNljEetn.mstrb.cn
http://kSqDohwu.mstrb.cn
http://FEcXZn6Z.mstrb.cn
http://www.dtcms.com/a/229497.html

相关文章:

  • 前缀和基础训练
  • STM32H562----------ADC外设详解
  • Abaqus连接器弹片正向力分析:
  • MMAD论文精读
  • 【FAQ】HarmonyOS SDK 闭源开放能力 —Account Kit(5)
  • spring boot应答500问题跟踪
  • Docker基础命令
  • 图片组件|纯血鸿蒙组件库AUI
  • 小白的进阶之路系列之十一----人工智能从初步到精通pytorch综合运用的讲解第四部分
  • JS对数据类型的检测
  • 前端开发处理‘流式数据’与‘非流式数据’,在接收完整与非完整性数据时应该如何渲染和使用
  • 从零开始构建文本统计模型:字符级与多字符片段频率分析实践
  • java30
  • HCIP(BGP综合实验)
  • linux批量创建文件
  • RHEL7安装教程
  • 【QT】自定义QWidget标题栏,可拖拽(拖拽时窗体变为normal大小),可最小/大化、关闭(图文详情)
  • Spring AI之RAG入门
  • SpringBoot3.2新特性:JdbcClient
  • 模块化交互数字人系统:OpenAvatarChat,单台PC即可运行完整功能
  • 【Redis】大key对持久化的影响
  • 定时器时钟来源可以从输入捕获引脚输入
  • Unity ARPG战斗系统 _ RootMotion相关知识点
  • GPTBots在AI大语言模型应用中敏感数据匿名化探索和实践
  • 基于InternLM的情感调节大师FunGPT
  • agent mode 代理模式,整体要求,系统要求, 系统指令
  • 2025年微信小程序开发:AR/VR与电商的最新案例
  • [Python] struct.unpack() 用法详解
  • 深入理解前端DOM:现代Web开发的基石
  • Tauri(2.5.1)+Leptos(0.7.8)开发桌面应用--简单的工作进度管理