查看“Joystick Controls DC Motor”的源代码
←
Joystick Controls DC Motor
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{Language| Joystick Controls DC Motor}} {| style="width: 800px;" |- | ==Objective== To control rotation of DC motor by Joystick. ==Principle== By detecting Joystick analog values in X- and Y-axes, you can control the rotation and direction of the DC motor. ==Equipment== {|class="wikitable" |- |Module||Number||Function |- |[[Microduino-CoreUSB]]||1||Core board |- |[[Microduino-Sensorhub]]||1||Sensor pinboard |- | [[Microduino-Joystick]]||1||Joystick sensor |- | [[Microduino-Robot]]||1||Robot control board |- | [[Microduino-Motor]]||1||DC motor drive board |- | [[Motor]]||1|| |} [[File:_Joystick_motor.jpg|600px|center|thumb]] ==Hardware Buildup== *Setup 1:Stack CoreUSB, Robot, Motor and Sensorhub. [[File:CoreUSB_Robot_Sensorhub.jpg|600px|center|thumb]] *Setup 2:Connect Joystick to Sensorhub to A0-A1 pin of Sensorhub and motor to OUTA-OUT1B pin of Stepper. [[file:Microduino-sensorhub_Joystick.JPG|thumb|800px|center]] [[File:Joystick_Motor_sensor.jpg|600px|center|thumb]] ==Software Debugging== *Define pin of Joystick and motor control. <source lang="cpp"> #define PI 3.1415926 #define JoystickX_PIN A1 //Joystick X-axis output #define JoystickY_PIN A0 //Joystick Y-axis output #define PIN_MOTORA 5 //Motor output #define PIN_MOTORB 6 // Motor output pin </source> *Calculate the angle where Joystick lies, according to which you can control rotation speed and decide rotation direction based on positive or negative value of the angle. <source lang="cpp"> valueX = (float)(analogRead(JoystickX_PIN)-512); valueY = (float)(analogRead(JoystickY_PIN)-512); valueL = sqrt(sq(valueX)+sq(valueY)); angle = asin(valueX/valueL)*180/PI; // Calculate the angle of Joystick by inverse trigonometric function motorSpeed = (int)(angle*255/180); // Calculate rotation speed according to the angle. if(motorSpeed > 0) // If the angle is positive, then the motor rotates clockwise. { digitalWrite(PIN_MOTORA, LOW); analogWrite(PIN_MOTORB, motorSpeed); } else if(motorSpeed < 0) //If the angle is negative, then the motor rotates anti-clockwise. { digitalWrite(PIN_MOTORB, LOW); analogWrite(PIN_MOTORA, abs(motorSpeed)); } else //If the angle is zero, then the motor stops rotation. { digitalWrite(PIN_MOTORA, LOW); digitalWrite(PIN_MOTORB, LOW); } delay(500); </source> ==Program== [[https://github.com/Microduino/Microduino_Tutorials/tree/master/MCookie_Tutorial/MicroduinoJoystickMotor MicroduinoJoystickMotor]] ==Result== Push Joystick to different angle, you can see the rotation speed and direction will change accordingly. ==Video== |}
该页面使用的模板:
模板:Language
(
查看源代码
)
模板:Nmbox
(
查看源代码
)
返回至
Joystick Controls DC Motor
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息