查看“Simulate voltage meter”的源代码
←
Simulate voltage meter
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{| style="width: 800px;" |- | ==Objective== The course will show you how to simulate a multimeter with Microduino. The reading of the “multimeter” will be displayed on Processing. ==Equipment== *'''[[Microduino-Core]]''' *'''[[Microduino-FT232R]]''' *Other Equipment **A USB cable **A bread board **A resistor of 1M Ω **A resistor of 100K Ω **A box of jumpers ==Schematic Diagram== [[File:AnalogVoltmeterConnectionDiagram.jpg|600px|center|thumb]] The schematic diagram adopts A2 pin. There are four channels totally, corresponding to the pins of A0, A1, A2, A3 respectively. The voltage reading will be displayed in Channel One. ==Program== Referring to AnalogVoltmeter AnalogVoltmeterProcessing ==Debugging== Step 1:Building the schematic diagram according to hardware environment, as follows: [[File:AnalogVoltmeterConnection.jpg|600px|center|thumb]] Step 2:Here is the code we need: The code of the two ends (Processing and Microduino) Microduino: //The voltage value will be received by Processing via serial port output void loop() { // take a number of analog samples and add them up while (sample_count < NUM_SAMPLES) { // sample each channel A2 to A5 for (l_cnt = 0; l_cnt < 4; l_cnt++) { sum[l_cnt] += analogRead(A2 + l_cnt); } sample_count++; delay(10); } // calculate the voltage for each channel for (l_cnt = 0; l_cnt < 4; l_cnt++) { voltage[l_cnt] = ((float)sum[l_cnt] / (float)NUM_SAMPLES * V_REF) / 1024.0; } // each voltage is multiplied by the resistor network // division factor to calculate the actual voltage voltage[0] = voltage[0] * DIV_1; voltage[1] = voltage[1] * DIV_2; voltage[2] = voltage[2] * DIV_3; voltage[3] = voltage[3] * DIV_4; // send voltages to Processing application via serial port / USB // voltage 1 - A (pin A2) Serial.print("A "); Serial.print(voltage[0], 1); Serial.print("V "); // voltage 2 - B (pin A3) Serial.print("B "); Serial.print(voltage[1], 1); Serial.print("V "); // voltge 3 - C (pin A4) Serial.print("C "); Serial.print(voltage[2], 1); Serial.print("V "); // voltage 4 - D (pin A5) Serial.print("D "); Serial.print(voltage[3], 1); Serial.print("V "); Serial.println(""); delay(10); // reset count and sums sample_count = 0; for (l_cnt = 0; l_cnt < 4; l_cnt++) { sum[l_cnt] = 0; } } Processing: //After getting the data of the first serial port println(Serial.list()); // modify Serial.list()[0] to select correct serial port ser_port = new Serial(this, Serial.list()[0], 9600); Function Description: Serial Event: serialEvent(Serial p) Displaying the channel and voltage: voltage (int channel, String volts) Drawing graph axis: DrawGraphAxis(int pos_x, int pos_y, int width, int height) Drawing graph: DrawGraph (String voltage, int channel, int pos_x, int pos_y, int scale) Drawing scale and radio box: DrawScaleSelect (int x_pos, int y_pos, int scale) Step 3:Uploading the code and compiling successfully. Step 4:Finding a battery or something similar and putting it between the red and the black lines, then watching the reading on the screen. Please refer to the image above. ==Result== The voltage reading of the A5 pin will be displayed in Channel Four on the screen, just as follows: [[File:AnalogVoltmeterResult.jpg|600px|center|thumb]] ==Video== |}
返回至
Simulate voltage meter
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
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
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息