查看“Control DC motor”的源代码
←
Control DC motor
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{| style="width: 800px;" |- | ==Objective== The course will show you how to use “Processing” to control the speed of the DC motor. ==Equipment== *'''[[Microduino-Core]]''' *'''[[Microduino-FT232R]]''' *Other Hardware Equipment **A USB cable **A box of jumpers **A breadboard **A DC motor **A potentiometer **A resistor of 2.2K Ω **A diode **A transistor NPN ==Schematic== [[File:processingDCMotorSchematics.jpg|600px|center|thumb]] ==Program== Refer to MicroduinoDCMotorControl ProcessingDCMotorControl ==Debugging== Step 1:Build hardware environment in accord with the schematic, just like this: [[File:processingDCMotorConnectionDiagram.jpg|600px|center|thumb]] Step 2:Here the code we need: The code of the two ends (Processing and Microduino) Microduino: //Send output value to the motor after getting the serial data if(Serial.available())//if serial is available { leitura=Serial.read();//read serial data Serial.println(leitura); vel=map(leitura,0,255,0,1023);//map if(leitura>0)//run motor by leitura { analogWrite(motorPin,vel); delay(1); } else//stop motor { analogWrite(motorPin,LOW); } } Processing: //List all the serial ports and get data of the first serial port // List all the available serial ports in the output pane. // You will need to choose the port that the Wiring board is // connected to from this list. The first port in the list is // port #0 and the third port in the list is port #2. println(Serial.list()); // Open the port that the Wiring board is connected to (in this case #0) // Make sure to open the port at the same speed Wiring is using (9600bps) port = new Serial(this, Serial.list()[0], 9600); //Draw and update void draw() { background(0); update(mouseX/10); println(mouseX); } //Transmit the x-coordinate value of the mouse through the serial port and draw the current value on Processing void update(int x) { port.write(x); stroke(255); line(mouseX, 0, mouseX, 160); text (mouseX, mouseX, 180); } Step 3:Download the code and compile successfully. . Step 4:Move your mouse around in “Processing” after the system goes well to see speed change of the motor. ==Result== A simple speed indicator will be displayed on the screen. The speed of the motor will change along with the change of your mouse on the x-coordinate. [[File:processingDCMotorResult.jpg|600px|center|thumb]] ==Video== |}
返回至
Control 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
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息