<view class="wx_h">
<text>点阵屏实时画图案</text>
<view class="line"></view>
</view>
.wx_h {
padding-top: 20px;
padding-bottom: 35px;
margin-left: 4px;
font-size: 19px;
text-align: center;
}
.line {
margin-top: 10px;
width: 99%;
height: 1rpx;
background: #731496;
}
import bleComm from '../utils/bleComm.js';
Page({
data: {
objectArray: [{
id: 63,
bk: false
}],
},
onUnload: function() {
bleComm.disConnect();
},
onHide: function() {
bleComm.disConnect();
},
})
mport bleComm from '../utils/bleComm.js';
Page({
data: {
objectArray: [{
id: 63,
bk: false
}],
},
onUnload: function() {
bleComm.disConnect();
},
onHide: function() {
bleComm.disConnect();
},
onLoad: function() {
for (let i = 62; i >= 0; i--) {
this.data.objectArray = [{
id: i,
bk: false
}].concat(this.data.objectArray)
this.setData({
objectArray: this.data.objectArray,
})
}
console.log(this.data.objectArray);
},
})
<view class="wx_h">
<text>点阵屏实时画图案</text>
<view class="line"></view>
</view>
<view class="padbk"><!-- 背景颜色 -->
<view class="pad"></view><!-- 设定第一行点距离背景高度 -->
<!-- 使用wx:for 将64个点画出来并添加点击事件-->
<view class="pad1 bt-no-bk" wx:for="{{objectArray}}" id="{{item.id}}" wx:key="{{item.id}}" bindtap="listClick"></view>
</view>
.wx_h {
padding-top: 20px;
padding-bottom: 35px;
margin-left: 4px;
font-size: 19px;
text-align: center;
}
.line {
margin-top: 10px;
width: 99%;
height: 1rpx;
background: #731496;
}
.padbk {
background-color: #404040;
}
.pad {
height: 5px;
}
.pad1 {
width: 41.5px;
height: 41.5px;
margin-left: 4.8px;
border-radius: 8px;
display: inline-flex;
}
.bt-no-bk {
background-color: #fff;
}
listClick: function (event) {
var id = parseInt(event.currentTarget.id);
console.log('(', id, ',', this.data.objectArray[id].bk, ')');
},
listClick: function (event) {
var id = parseInt(event.currentTarget.id);
var x = id % 8;
var y = parseInt(id / 8);
this.data.objectArray[id].bk = !this.data.objectArray[id].bk;
this.setData({//更新数据
objectArray: this.data.objectArray,
})
console.log('(', x, ',', y, ',', this.data.objectArray[id].bk, ')');
},
<view class="pad1 {{item.bk?'bt-red-bk':'bt-no-bk'}}" wx:for="{{objectArray}}" id="{{item.id}}" wx:key="{{item.id}}" bindtap="listClick"></view>
listClick: function (event) {
var id = parseInt(event.currentTarget.id);
var x = id % 8;
var y = parseInt(id / 8);
this.data.objectArray[id].bk = !this.data.objectArray[id].bk;
this.setData({
objectArray: this.data.objectArray,
})
var msg;
if (this.data.objectArray[id].bk) {
msg = x * 100 + y * 10 + 1;
}
else {
msg = x * 100 + y * 10;
}
console.log('(', x, ',', y, ',', msg, ')');
bleComm.writeValue(msg.toString() + "\n");
},
onLoad: function() {
wx.showLoading({
title: '靠近连接',
mask: true
})
bleComm.connectDevice().then(res => {
wx.showToast({
title: '蓝牙连接成功',
icon: 'success',
duration: 300
})
});
for (let i = 62; i >= 0; i--) {
this.data.objectArray = [{
id: i,
bk: false
}].concat(this.data.objectArray)
this.setData({
objectArray: this.data.objectArray,
})
}
console.log(this.data.objectArray);
},
#include <Microduino_Matrix.h>
uint8_t Addr[MatrixPix_X][MatrixPix_Y] = //1x1
{
{64} //点阵IIC地址
};
Matrix display = Matrix(Addr, TYPE_COLOR);//创建一个点阵屏方法
static const uint8_t logoA[] PROGMEM = //低位在前 逐行
{
0x00, 0x00, 0x14, 0x2A, 0x2A, 0x2A, 0x00, 0x00
};
void setup()
{
Wire.begin();//初始化I2C接口
delay(3000);//等待点阵屏初始化
Wire.begin();//初始化I2C接口
display.setBrightness(255);//设置屏幕亮度
display.clearDisplay();//清除屏幕
display.setColor(0, 255, 0);//设置颜色
display.drawBMP(0, 0, 8, 8, logoA); //画图BMP图 x,y,w,h,data
delay(2000);
display.clearDisplay();
}
void loop()
{
display.setLedColor(1, 1, 155, 0, 0);//横坐标,纵坐标,r,g,b
}
if (my_Serial.available() > 0)
{
char c = my_Serial.read();//读取一个字符
if (c != '\n') //如果不是'\n'
{
str += c;//拼接字符
}
else //接收完毕
{
str = "";//清空字符,下次重新接收
}
}
String str;
void showMatrix(int data)
{
uint8_t x = data / 100;//百位数字
uint8_t y = data / 10 % 10;//十位数字
uint8_t color = data % 10;//个位数字
if (color)//根据个位数字控制颜色
display.setLedColor(x, y, 155, 0, 0);
else
display.setLedColor(x, y, 0, 0, 0);
}
#include <Microduino_Matrix.h>
//#define BLEMODULE_01_9600 //old-mCookie_Bluetooth
//#define BLEMODULE_45_9600 //Microduino_BLE new-mCookie_Bluetooth
#define BLEMODULE_01_57600 //mCenter+、BleUpload
/*定义串口0接口,波特率9600的蓝牙*/
#ifdef BLEMODULE_01_9600
#define my_Serial Serial
#define UARTSPEED 9600
#endif
/*定义串口0接口,波特率57600的蓝牙*/
#ifdef BLEMODULE_01_57600
#define my_Serial Serial
#define UARTSPEED 57600
#endif
/*定义软串口(4,5)接口,波特率9600的蓝牙*/
#ifdef BLEMODULE_45_9600
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 5);
#define my_Serial mySerial
#define UARTSPEED 9600
#endif
uint8_t Addr[MatrixPix_X][MatrixPix_Y] = //1x1
{
{64} //点阵IIC地址
};
Matrix display = Matrix(Addr, TYPE_COLOR);
static const uint8_t logoA[] PROGMEM = //低位在前 逐行
{
0x00, 0x00, 0x14, 0x2A, 0x2A, 0x2A, 0x00, 0x00
};
String str;
void showMatrix(int data)
{
uint8_t x = data / 100;//百位数字
uint8_t y = data / 10 % 10;//十位数字
uint8_t color = data % 10;//个位数字
if (color)//根据个位数字控制颜色
display.setLedColor(x, y, 155, 0, 0);
else
display.setLedColor(x, y, 0, 0, 0);
}
void setup()
{
Serial.begin(115200);
my_Serial.begin(UARTSPEED);//设置蓝牙通信波特率
delay(3000);
Wire.begin();
display.setBrightness(255);
display.clearDisplay();
display.setColor(0, 255, 0);
display.drawBMP(0, 0, 8, 8, logoA); //x,y,w,h,data
delay(2000);
display.clearDisplay();
}
clear: function () {
for (let i = 63; i >= 0; i--) {
this.data.objectArray[i].bk = false;
}
this.setData({
objectArray: this.data.objectArray,
})
console.log("-1")
bleComm.writeValue("-1\n");
},
void showMatrix(int data)
{
if (data == -1)
display.clearDisplay();
else
{
uint8_t x = data / 100;//百位数字
uint8_t y = data / 10 % 10;//十位数字
uint8_t color = data % 10;//个位数字
if (color)//根据个位数字控制颜色
display.setLedColor(x, y, 155, 0, 0);
else
display.setLedColor(x, y, 0, 0, 0);
}
}
<radio-group bindchange="radioChange">
<label class="radio" wx:for="{{items}}" wx:key="{{item.id}}">
<radio class="radiopad" color="{{radiocolor[item.name-1]}}" value="{{item.name}}" checked="{{item.checked}}" />
<text class="textpad">{{item.value}}</text>
</label>
</radio-group>
objectArray: [
{ id: 63, color: 0, bk: false }
],
radioChange: function (e) {
mycolor = parseInt(e.detail.value);
},
<view class="pad1 {{item.bk?sscolor[item.color-1]:'bt-no-bk'}}" wx:for="{{objectArray}}" bindtap="listClick" id="{{item.id}}" wx:key="{{item.id}}"></view>
this.data.objectArray[id].color = mycolor;
var msg;
if (this.data.objectArray[id].bk){
msg = x * 100 + y * 10 + mycolor;
}
else{
msg = x * 100 + y * 10 ;
}
uint8_t setcolor[7][3]
{
{0, 0, 0},
{155, 0, 0},
{155, 155, 0},
{50, 255, 130},
{0, 155, 155},
{0, 0, 155},
{155, 0, 155}
};
void showMatrix(int data)
{
if (data == -1)
display.clearDisplay();
else
{
uint8_t x = data / 100;
uint8_t y = data / 10 % 10;
uint8_t color = data % 10;
display.setLedColor(x, y, setcolor[color][0], setcolor[color][1], setcolor[color][2]);
}
}
END
杨立斌
美科
解惑
创建时间:2017/12/22
31点阵屏