android蓝牙单片机显示波形Word文档下载推荐.docx

上传人:b****3 文档编号:14000054 上传时间:2022-10-16 格式:DOCX 页数:15 大小:202.98KB
下载 相关 举报
android蓝牙单片机显示波形Word文档下载推荐.docx_第1页
第1页 / 共15页
android蓝牙单片机显示波形Word文档下载推荐.docx_第2页
第2页 / 共15页
android蓝牙单片机显示波形Word文档下载推荐.docx_第3页
第3页 / 共15页
android蓝牙单片机显示波形Word文档下载推荐.docx_第4页
第4页 / 共15页
android蓝牙单片机显示波形Word文档下载推荐.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

android蓝牙单片机显示波形Word文档下载推荐.docx

《android蓝牙单片机显示波形Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《android蓝牙单片机显示波形Word文档下载推荐.docx(15页珍藏版)》请在冰豆网上搜索。

android蓝牙单片机显示波形Word文档下载推荐.docx

图一是最后的图,图二只是演示可以画出正弦波,其中按钮开启蓝牙是直接默认连接一个设备,按钮sin是开始接受蓝牙数据并画图,图示中由于没有开蓝牙,故一直接收数据一直为0所以是画出的一条直线,关于清除,是因为在画布下方还有一个TextView空间使用来显示接受到的数据的。

图一图二

关于程序:

其中的注释我已经写的很清楚

在manifest中,添加蓝牙权限:

<

/application>

<

uses-permissionandroid:

name="

android.permission.BLUETOOTH"

/>

android.permission.BLUETOOTH_ADMIN"

/manifest>

 

在main.xml:

?

xmlversion="

1.0"

encoding="

utf-8"

>

LinearLayoutxmlns:

android="

"

android:

layout_width="

fill_parent"

layout_height="

orientation="

vertical"

>

TextView

wrap_content"

text="

@string/hello"

LinearLayout

android:

horizontal"

Button

id="

@+id/button"

@string/button"

<

@+id/sin"

@string/sin"

Button

android:

@+id/clear"

@string/clear"

/LinearLayout>

SurfaceView

@+id/show"

TextView

@+id/myview"

@string/myview"

/>

在strings.xml:

resources>

stringname="

hello"

HelloWorld,OscilloscopeActivity!

/string>

app_name"

Oscilloscope<

button"

开启蓝牙<

myview"

参数显示:

sin"

sin<

buttonstart"

搜索<

buttonselect"

选择设备<

buttonsend"

发送<

input"

pleaseinput<

clear"

清除<

/resources>

在Oscilloscope.java

packagecom.ways;

importjava.io.IOException;

importjava.io.InputStream;

importjava.io.OutputStream;

importjava.util.Iterator;

importjava.util.Set;

importjava.util.Timer;

importjava.util.TimerTask;

importjava.util.UUID;

importandroid.app.Activity;

importandroid.bluetooth.BluetoothAdapter;

importandroid.bluetooth.BluetoothDevice;

importandroid.bluetooth.BluetoothSocket;

importandroid.content.Intent;

importandroid.graphics.Canvas;

importandroid.graphics.Color;

importandroid.graphics.Paint;

importandroid.graphics.Rect;

importandroid.os.Bundle;

importandroid.os.Handler;

importandroid.os.Message;

importandroid.view.Menu;

importandroid.view.MenuItem;

importandroid.view.SurfaceHolder;

importandroid.view.SurfaceView;

importandroid.view.View;

importandroid.view.SurfaceHolder.Callback;

importandroid.view.View.OnClickListener;

importandroid.widget.Button;

importandroid.widget.TextView;

publicclassOscilloscopeextendsActivity{

/**Calledwhentheactivityisfirstcreated.*/

finalintHEIGHT=320;

//设置画图范围高度

finalintWIDTH=450;

//画图范围宽度

finalintX_OFFSET=5;

//x轴(原点)起始位置偏移画图范围一点

privateintcx=X_OFFSET;

//实时x的坐标

intcenterY=HEIGHT/2;

//y轴的位置

TextViewmyview=null;

//画布下方显示获取数据的地方

finalUUIDuuid=UUID.fromString("

00001101-0000-1000-8000-00805F9B34FB"

);

//uuid此为单片机蓝牙模块用

//还有其他的uuid,这个可以再XX查到,暂不清楚其中的差别

finalBluetoothAdaptermBluetoothAdapter=BluetoothAdapter.getDefaultAdapter();

//获取本手机的蓝牙适配器

staticintREQUEST_ENABLE_BT=1;

//一个常量而已,开启蓝牙时使用

BluetoothSocketsocket=null;

//用于数据传输的socket

intREAD=1;

//一个常量,用于传输数据消息队列的识别字

publicConnectedThreadthread=null;

//连接蓝牙设备线程

staticinttemp=0;

//临时变量用于保存接收到的数据

privateSurfaceHolderholder=null;

//画图使用,可以控制一个SurfaceView

privatePaintpaint=null;

//画笔

SurfaceViewsurface=null;

//

Timertimer=newTimer();

//一个时间控制的对象,用于控制实时的x的坐标,

//使其递增,类似于示波器从前到后扫描

TimerTasktask=null;

//时间控制对象的一个任务

/*关于画图类的几点说明

*SurfaceView是View的继承类,这个视图里

*内嵌了一个专门用于绘制的Surface。

可以控制这个Surface的格式和尺寸。

*SurfaceView控制这个Surface的绘制位置。

*

*实现过程:

继承SurfaceVi

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1