@目录
一整套的简易计分器
Android端地址
计算机python端
Arduino Nano端
掌控板端
咳咳,图片有限使用
创作故事
来源于乒乓球……
经常和家里的小伙打打球,
来,好好打
latter……
几比几了?或者 轮到谁发球了?
于是网络上搜索了一波,并没有我想要的计分器
于是自己做一个(然后没想到做起了一套)
mpython X(类mpython)创作
语言:python
操作与函数
使用的虽是python但要满足mpython语法(规则)
A、B按键实现计数增加
#A键
def on_button_a_down(_):
global sever, severhelp, totallscore, p2score, p1score, historyp1s, historyp2s
time.sleep_ms(10)
if button_a.value() == 1: return
historyp1s = p1score
p1score = p1score + 1
time.sleep(1)
displayupdate()
button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)
#B键
def on_button_b_down(_):
global sever, severhelp, totallscore, p2score, p1score, historyp1s, historyp2s
time.sleep_ms(10)
if button_b.value() == 1: return
historyp2s = p2score
p2score = p2score + 1
time.sleep(1)
displayupdate()
button_b.irq(trigger=Pin.IRQ_FALLING, handler=on_button_b_down)
摇一摇撤销操作
_is_shaked = _is_thrown = False
_last_x = _last_y = _last_z = _count_shaked = _count_thrown = 0
def on_shaked():pass
def on_thrown():pass
tim11 = Timer(11)
def timer11_tick(_):
global _is_shaked, _is_thrown, _last_x, _last_y, _last_z, _count_shaked, _count_thrown
if _is_shaked:
_count_shaked += 1
if _count_shaked == 5: _count_shaked = 0
if _is_thrown:
_count_thrown += 1
if _count_thrown == 10: _count_thrown = 0
if _count_thrown > 0: return
x=accelerometer.get_x(); y=accelerometer.get_y(); z=accelerometer.get_z()
_is_thrown = (x * x + y * y + z * z < 0.25)
if _is_thrown: on_thrown();return
if _last_x == 0 and _last_y == 0 and _last_z == 0:
_last_x = x; _last_y = y; _last_z = z; return
diff_x = x - _last_x; diff_y = y - _last_y; diff_z = z - _last_z
_last_x = x; _last_y = y; _last_z = z
if _count_shaked > 0: return
_is_shaked = (diff_x * diff_x + diff_y * diff_y + diff_z * diff_z > 1)
if _is_shaked: on_shaked()
tim11.init(period=100, mode=Timer.PERIODIC, callback=timer11_tick)
def on_shaked():
global sever, severhelp, totallscore, p2score, p1score, historyp1s, historyp2s
if p1score == historyp1s + 1:
p1score = historyp1s
historyp1s = p1score
displayupdate()
if p2score == historyp2s + 1:
p2score = historyp2s
historyp2s = p2score
displayupdate()
#引入触摸“python”文字控制
def timer12_tick(_):
global _status_p, _status_y, _status_t, _status_h, _status_o, _status_n
try:
touchPad_P.read();pass
except:
return
if touchPad_P.read() < 400:
if 1 != _status_p:_status_p = 1;on_touchpad_P_pressed()
elif 0 != _status_p:_status_p = 0;on_touchpad_P_unpressed()
if touchPad_Y.read() < 400:
if 1 != _status_y:_status_y = 1;on_touchpad_Y_pressed()
elif 0 != _status_y:_status_y = 0;on_touchpad_Y_unpressed()
if touchPad_T.read() < 400:
if 1 != _status_t:_status_t = 1;on_touchpad_T_pressed()
elif 0 != _status_t:_status_t = 0;on_touchpad_T_unpressed()
if touchPad_H.read() < 400:
if 1 != _status_h:_status_h = 1;on_touchpad_H_pressed()
elif 0 != _status_h:_status_h = 0;on_touchpad_H_unpressed()
if touchPad_O.read() < 400:
if 1 != _status_o:_status_o = 1;on_touchpad_O_pressed()
elif 0 != _status_o:_status_o = 0;on_touchpad_O_unpressed()
if touchPad_N.read() < 400:
if 1 != _status_n:_status_n = 1;on_touchpad_N_pressed()
elif 0 != _status_n:_status_n = 0;on_touchpad_N_unpressed()
tim12.init(period=100, mode=Timer.PERIODIC, callback=timer12_tick)
def on_touchpad_P_pressed():
global sever, severhelp, totallscore, p2score, p1score, historyp1s, historyp2s
# 不形成负数形式分数&撤销
if p1score != 0:
p1score = p1score + -1
displayupdate()
# 设定发球者
if totallscore == 0:
sever = 3
severhelp = severhelp + 1
displayupdate()
def on_touchpad_N_pressed():
global sever, severhelp, totallscore, p2score, p1score, historyp1s, historyp2s
# 不形成负数形式分数&撤销
if p2score != 0:
p2score = p2score + -1
displayupdate()
# 设定发球者
if totallscore == 0:
sever = 4
severhelp = severhelp + 1
displayupdate()
def on_touchpad_H_pressed():#重置
global sever, severhelp, totallscore, p2score, p1score, historyp1s, historyp2s
p1score = 0
p2score = 0
totallscore = 0
severhelp = 1
sever = 0
oled.fill(0)
oled.show()
time.sleep(1)
displayupdate()
显示
运用模拟数码管显示
def display_font(_font, _str, _x, _y, _wrap, _z=0):
_start = _x
for _c in _str:
_d = _font.get_ch(_c)
if _wrap and _x > 128 - _d[2]: _x = _start; _y += _d[1]
if _c == '1' and _z > 0: oled.fill_rect(_x, _y, _d[2], _d[1], 0)
oled.blit(framebuf.FrameBuffer(bytearray(_d[0]), _d[2], _d[1],
framebuf.MONO_HLSB), (_x+int(_d[2]/_z)) if _c=='1' and _z>0 else _x, _y)
_x += _d[2]
只运用一个“显示更新”[displayupdate()]函数,在Mind+中由于显示问题直接使用多线程保持屏幕最新
Mind+创作
语言:arduino C
// 动态变量
volatile float mind_n_p1score, mind_n_p2score, mind_n_totallscore, mind_n_sevehelp,
mind_n_sever, mind_n_historyp1s, mind_n_historyp2s;
// 函数声明
void DF_p1sdiaplay();
void DF_p2sdiaplay();
void ShakeEvent();
void pin13TouchCallback();
void onButtonAPressed();
void DF_displayupdate();
void onButtonBPressed();
void pin27TouchCallback();
void pin4TouchCallback();
newTask(loop1)
newTask(loop2)
显示
//显示
// 静态常量
const uint8_t imageMatrix[][120] = {
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xf8,0x0,0xf0,0xf8,0x0,0xf0,0xf8,0x0,0xf0,0xf8,0x0,0xf0,0xc4,0x1,0x10,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xe7,0xfe,0x30,0xe7,0xff,0x70,0xf7,0xff,0x70,0xe7,0xfe,0x30,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xc3,0xfe,0x10,0xc3,0xff,0x10,0xc4,0x1,0x10,0xe4,0x0,0xf0,0xf8,0x0,0xf0,0xf8,0x0,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0},
{0xff,0xff,0xff,0x80,0xff,0xff,0xff,0x80,0xff,0xf7,0xff,0x80,0xff,0xf,0xff,0x80,0xfe,0x18,0xff,0x80,0xfe,0x30,0xff,0x80,0xff,0x60,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xe1,0xff,0x80,0xff,0xf7,0xff,0x80,0xff,0xff,0xff,0x80,0xff,0xf3,0xff,0x80,0xff,0xe1,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xc0,0xff,0x80,0xff,0xf3,0xff,0x80,0xff,0xff,0xff,0x80,0xff,0xff,0xff,0x80,0xff,0xff,0xff,0x80},
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xe0,0x0,0xf0,0xc0,0x0,0xf0,0x80,0x1,0xb0,0xc0,0x3,0x10,0xe0,0x2,0x10,0xff,0xfc,0x10,0xff,0xfc,0x10,0xff,0xfc,0x30,0xff,0xfc,0x10,0xff,0xfc,0x10,0xff,0xfc,0x10,0xf8,0x2,0x10,0xf0,0x3,0x30,0xf0,0x1,0xf0,0xf0,0x0,0xf0,0x88,0x0,0xf0,0x87,0xff,0xf0,0x87,0xff,0xf0,0x87,0xff,0xf0,0x87,0xff,0xf0,0x87,0xff,0xf0,0x87,0xff,0xf0,0x88,0x0,0xf0,0x98,0x0,0x70,0xb0,0x0,0x30,0xe0,0x0,0x30,0xe0,0x0,0x70,0xff,0xff,0xf0},
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xe0,0x0,0x70,0xc0,0x0,0x70,0xc0,0x0,0xb0,0xe0,0x1,0x10,0xf0,0x3,0x10,0xff,0xfe,0x10,0xff,0xfe,0x10,0xff,0xfe,0x10,0xff,0xfe,0x10,0xff,0xfe,0x10,0xf0,0x6,0x10,0xe0,0x2,0x30,0xc0,0x0,0x70,0xc0,0x1,0x70,0xe0,0x3,0x30,0xf0,0x6,0x30,0xff,0xfe,0x10,0xff,0xfe,0x10,0xff,0xfe,0x10,0xff,0xfe,0x10,0xff,0xfe,0x10,0xf0,0x2,0x10,0xe0,0x1,0x10,0xc0,0x0,0x90,0xc0,0x0,0xf0,0xe0,0x0,0x70,0xff,0xff,0xf0,0xff,0xff,0xf0},
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xe7,0xfe,0x70,0xc3,0xfe,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xe3,0x4,0x30,0xf0,0x0,0x70,0xfc,0x1,0x70,0xfe,0x2,0x70,0xff,0x6,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfe,0x70,0xff,0xfe,0x70,0xff,0xff,0xf0,0xff,0xff,0xf0},
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xf0,0x0,0xf0,0xf0,0x0,0x70,0xd8,0x0,0x30,0xc8,0x0,0x30,0xc6,0x0,0x70,0xc3,0xff,0xf0,0xc3,0xff,0xf0,0xc3,0xff,0xf0,0xc3,0xff,0xf0,0xc3,0xff,0xf0,0xe3,0xff,0xf0,0xf2,0x7,0xf0,0xfc,0x3,0xf0,0xfc,0x1,0xf0,0xfc,0x2,0x70,0xfe,0x4,0x30,0xff,0xfc,0x30,0xff,0xfc,0x10,0xff,0xfc,0x10,0xff,0xfc,0x10,0xff,0xfc,0x10,0xff,0xfe,0x10,0xf0,0x1,0x30,0xe0,0x1,0xf0,0xe0,0x0,0xf0,0xf0,0x0,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0},
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xf8,0x0,0xf0,0xf0,0x0,0x70,0xf0,0x0,0x30,0xf8,0x0,0x30,0xc8,0x0,0x70,0x84,0x0,0xf0,0x87,0xff,0xf0,0x87,0xff,0xf0,0x87,0xff,0xf0,0x87,0xff,0xf0,0x87,0xff,0xf0,0x86,0x7,0xf0,0xc4,0x3,0xf0,0xc8,0x1,0xf0,0xe8,0x1,0xf0,0xc4,0x3,0xf0,0xc7,0xfe,0x70,0x87,0xfc,0x10,0x87,0xfc,0x10,0x87,0xfc,0x10,0x87,0xfc,0x10,0x87,0xfc,0x10,0x84,0x2,0x10,0xc8,0x3,0x10,0xe8,0x1,0xf0,0xf0,0x0,0xf0,0xf0,0x0,0xf0,0xff,0xff,0xf0},
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xe0,0x4,0xf0,0xc0,0x0,0xf0,0x80,0x0,0xf0,0x80,0x1,0xf0,0xc0,0x3,0x30,0xe0,0x6,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfe,0x70,0xff,0xfe,0xf0,0xff,0xfe,0x70,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfe,0x70,0xff,0xfe,0xf0,0xff,0xff,0xf0},
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xf8,0x3,0xf0,0xf0,0x0,0xf0,0xf0,0x0,0xf0,0xf0,0x1,0xf0,0x88,0x3,0x30,0x8f,0xfe,0x30,0x87,0xfc,0x30,0x87,0xfc,0x30,0x87,0xfc,0x30,0x87,0xfc,0x30,0x87,0xfc,0x30,0x84,0x4,0x30,0x88,0x0,0x30,0xd8,0x1,0x70,0xc8,0x3,0x30,0x84,0x6,0x30,0x87,0xfc,0x30,0x87,0xfc,0x30,0x87,0xfc,0x30,0x87,0xfc,0x30,0x87,0xfc,0x30,0x87,0xfe,0x30,0x88,0x3,0x30,0x90,0x1,0xf0,0xf0,0x0,0xf0,0xf0,0x1,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0},
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xfc,0x3,0xf0,0xf8,0x1,0xf0,0xf8,0x0,0xf0,0xf8,0x1,0xf0,0xc4,0x3,0x30,0xc3,0x6,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0xfc,0x30,0xc3,0x4,0x30,0xc2,0x0,0x70,0xe4,0x0,0x70,0xfc,0x3,0x70,0xfe,0x2,0x70,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xff,0xfc,0x30,0xf0,0x2,0x30,0xe0,0x1,0x30,0xe0,0x1,0x30,0xe0,0x0,0xf0,0xf0,0x1,0xf0,0xff,0xff,0xf0},
{0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xfc,0x3f,0xf0,0xf8,0x67,0xf0,0xf8,0xc7,0xf0,0xff,0x87,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x8f,0xf0,0xff,0xdf,0xf0,0xff,0xff,0xf0,0xff,0xdf,0xf0,0xff,0x8f,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0x7,0xf0,0xff,0xf,0xf0,0xff,0x9f,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0},
{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}
};
发球者判定
// 计算发球者
void loop1::setup() {
}
void loop1::loop() {
mind_n_totallscore = (mind_n_p1score+mind_n_p2score);
if ((((!(mind_n_sever==0)) && (mind_n_totallscore<=21)) && (((((int)mind_n_totallscore) % ((int)2))==0) && (mind_n_totallscore==mind_n_sevehelp)))) {
mind_n_sever += 1;
mind_n_sevehelp += 1;
delay(100);
DF_displayupdate();
}
if ((((!(mind_n_sever==0)) && (mind_n_totallscore>21)) && (mind_n_totallscore==mind_n_sevehelp))) {
mind_n_sever += 1;
mind_n_sevehelp += 1;
delay(100);
DF_displayupdate();
}
delay(100);
}
显示实时刷新
// 保持元素显示完全
void loop2::setup() {
}
void loop2::loop() {
DF_p1sdiaplay();
DF_p2sdiaplay();
if (((!(mind_n_sever==0)) && ((((int)mind_n_sever) % ((int)2))==0))) {
display.drawImage(5, 60, 50, 4, imageMatrix[11]);
}
else if (((!(mind_n_sever==0)) && ((((int)mind_n_sever) % ((int)2))==1))) {
display.drawImage(75, 60, 50, 4, imageMatrix[11]);
}
delay(1000);
}
玩家分数(图片显示)
// 玩家分数(图片显示)
// 玩家一分数(图片显示)
void DF_p1sdiaplay() {
if ((mind_n_p1score<=9)) {
if ((mind_n_p1score==0)) {
display.drawImage(20, 15, 20, 30, imageMatrix[0]);
}
if ((mind_n_p1score==1)) {
display.drawImage(20, 15, 25, 30, imageMatrix[1]);
}
if ((mind_n_p1score==2)) {
display.drawImage(20, 15, 20, 30, imageMatrix[2]);
}
if ((mind_n_p1score==3)) {
display.drawImage(20, 15, 20, 30, imageMatrix[3]);
}
if ((mind_n_p1score==4)) {
display.drawImage(20, 15, 20, 30, imageMatrix[4]);
}
if ((mind_n_p1score==5)) {
display.drawImage(20, 15, 20, 30, imageMatrix[5]);
}
if ((mind_n_p1score==6)) {
display.drawImage(20, 15, 20, 30, imageMatrix[6]);
}
if ((mind_n_p1score==7)) {
display.drawImage(20, 15, 20, 30, imageMatrix[7]);
}
if ((mind_n_p1score==8)) {
display.drawImage(20, 15, 20, 30, imageMatrix[8]);
}
if ((mind_n_p1score==9)) {
display.drawImage(20, 15, 20, 30, imageMatrix[9]);
}
}
else if (((mind_n_p1score-10)<10)) {
display.drawImage(20, 15, 20, 30, imageMatrix[10]);
if (((mind_n_p1score-10)==0)) {
display.drawImage(5, 15, 20, 30, imageMatrix[0]);
}
if (((mind_n_p1score-10)==1)) {
display.drawImage(25, 15, 25, 30, imageMatrix[1]);
}
if (((mind_n_p1score-10)==2)) {
display.drawImage(25, 15, 20, 30, imageMatrix[2]);
}
if (((mind_n_p1score-10)==3)) {
display.drawImage(25, 15, 20, 30, imageMatrix[3]);
}
if (((mind_n_p1score-10)==4)) {
display.drawImage(25, 15, 20, 30, imageMatrix[4]);
}
if (((mind_n_p1score-10)==5)) {
display.drawImage(25, 15, 20, 30, imageMatrix[5]);
}
if (((mind_n_p1score-10)==6)) {
display.drawImage(25, 15, 20, 30, imageMatrix[6]);
}
if (((mind_n_p1score-10)==7)) {
display.drawImage(20, 15, 20, 30, imageMatrix[7]);
}
if (((mind_n_p1score-10)==8)) {
display.drawImage(25, 15, 20, 30, imageMatrix[8]);
}
if (((mind_n_p1score-10)==9)) {
display.drawImage(25, 15, 20, 30, imageMatrix[9]);
}
}
}
// 玩家二分数(图片显示)
void DF_p2sdiaplay() {
if ((mind_n_p2score<=9)) {
if ((mind_n_p2score==0)) {
display.drawImage(75, 15, 20, 30, imageMatrix[0]);
}
if ((mind_n_p2score==1)) {
display.drawImage(75, 15, 25, 30, imageMatrix[1]);
}
if ((mind_n_p2score==2)) {
display.drawImage(75, 15, 20, 30, imageMatrix[2]);
}
if ((mind_n_p2score==3)) {
display.drawImage(75, 15, 20, 30, imageMatrix[3]);
}
if ((mind_n_p2score==4)) {
display.drawImage(75, 15, 20, 30, imageMatrix[4]);
}
if ((mind_n_p2score==5)) {
display.drawImage(75, 15, 20, 30, imageMatrix[5]);
}
if ((mind_n_p2score==6)) {
display.drawImage(75, 15, 20, 30, imageMatrix[6]);
}
if ((mind_n_p2score==7)) {
display.drawImage(75, 15, 20, 30, imageMatrix[7]);
}
if ((mind_n_p2score==8)) {
display.drawImage(75, 15, 20, 30, imageMatrix[8]);
}
if ((mind_n_p2score==9)) {
display.drawImage(75, 15, 20, 30, imageMatrix[9]);
}
}
else if (((mind_n_p2score-10)<10)) {
display.drawImage(70, 15, 20, 30, imageMatrix[10]);
if (((mind_n_p2score-10)==0)) {
display.drawImage(95, 15, 20, 30, imageMatrix[0]);
}
if (((mind_n_p2score-10)==1)) {
display.drawImage(95, 15, 25, 30, imageMatrix[1]);
}
if (((mind_n_p2score-10)==2)) {
display.drawImage(95, 15, 20, 30, imageMatrix[2]);
}
if (((mind_n_p2score-10)==3)) {
display.drawImage(95, 15, 20, 30, imageMatrix[3]);
}
if (((mind_n_p2score-10)==4)) {
display.drawImage(20, 15, 20, 30, imageMatrix[4]);
}
if (((mind_n_p2score-10)==5)) {
display.drawImage(95, 15, 20, 30, imageMatrix[5]);
}
if (((mind_n_p2score-10)==6)) {
display.drawImage(95, 15, 20, 30, imageMatrix[6]);
}
if (((mind_n_p2score-10)==7)) {
display.drawImage(95, 15, 20, 30, imageMatrix[7]);
}
if (((mind_n_p2score-10)==8)) {
display.drawImage(20, 15, 20, 30, imageMatrix[8]);
}
if (((mind_n_p2score-10)==9)) {
display.drawImage(95, 15, 20, 30, imageMatrix[9]);
}
}
}
显示更新函数
只有在这是会清空屏幕,如果在实时刷新的代码中加入清屏会导致屏幕频繁闪烁
// 显示更新
void DF_displayupdate() {
display.fillScreen(1);
DF_p1sdiaplay();
DF_p2sdiaplay();
if (((!(mind_n_sever==0)) && ((((int)mind_n_sever) % ((int)2))==0))) {
display.drawImage(5, 60, 50, 4, imageMatrix[11]);
}
else if (((!(mind_n_sever==0)) && ((((int)mind_n_sever) % ((int)2))==1))) {
display.drawImage(75, 60, 50, 4, imageMatrix[11]);
}
delay(1000);
}
摇动
//摇动撤销
void ShakeEvent() {
if ((mind_n_p1score==(mind_n_historyp1s+1))) {
mind_n_p1score = mind_n_historyp1s;
mind_n_historyp1s = mind_n_p1score;
DF_displayupdate();
}
if ((mind_n_p2score==(mind_n_historyp2s+1))) {
mind_n_p2score = mind_n_historyp2s;
mind_n_historyp2s = mind_n_p1score;
DF_displayupdate();
}
}
按键控制
//按键
//按键A
void onButtonAPressed() {
mind_n_historyp1s = mind_n_p1score;
mind_n_p1score += 1;
DF_displayupdate();
}
//按键B
void onButtonBPressed() {
mind_n_historyp2s = mind_n_p2score;
mind_n_p2score += 1;
DF_displayupdate();
}
触摸控制
//触摸
//串口27 P
void pin27TouchCallback() {
if ((!(mind_n_p1score==0))) {
mind_n_historyp1s = mind_n_p1score;
mind_n_p1score -= 1;
DF_displayupdate();
}
if ((mind_n_totallscore==0)) {
mind_n_sever = 3;
mind_n_sevehelp += 1;
DF_displayupdate();
}
}
//串口4 N
void pin4TouchCallback() {
if ((!(mind_n_p2score==0))) {
mind_n_historyp2s = mind_n_p1score;
mind_n_p2score -= 1;
DF_displayupdate();
}
if ((mind_n_totallscore==0)) {
mind_n_sever = 4;
mind_n_sevehelp += 1;
DF_displayupdate();
}
}
//串口13 H
void pin13TouchCallback() {
mind_n_p1score = 0;
mind_n_p2score = 0;
mind_n_totallscore = 0;
mind_n_sever = 0;
mind_n_sevehelp = 1;
display.fillScreen(1);
DF_displayupdate();
}
以上都未添加物联网功能
物联网
先联网
my_wifi = wifi()
my_wifi.connectWiFi("**", "**")
DFRobot_Iot myIot;
myIot.wifiConnect("yourSSID", "yourPASSWD");
mpython
#物联网连接与消息控制
mqtt = MQTTClient("**", "**", 1883, "**", "**", keepalive=30)
try:
mqtt.connect()
print('Connected')
except:
print('Disconnected')
def mqtt_topic_77523673456d755767(_msg):
global iotrece, sever, severhelp, totallscore, p2score, p1score, historyp2s, historyp1s, iotstate, iotmsg
iotrece = _msg
def mqtt_callback(topic, msg):
try:
topic = topic.decode('utf-8', 'ignore')
_msg = msg.decode('utf-8', 'ignore')
eval('mqtt_topic_' + bytes.decode(ubinascii.hexlify(topic)) + '("' + _msg + '")')
except: print((topic, msg))
mqtt.set_callback(mqtt_callback)
mqtt.subscribe("")
def timer14_tick(_):
mqtt.ping()
tim14 = Timer(14)
tim14.init(period=20000, mode=Timer.PERIODIC, callback=timer14_tick)
def thread_3():
global iotrece, sever, severhelp, totallscore, p2score, p1score, historyp2s, historyp1s, iotstate, iotmsg
while True:
if iotstate == True and my_wifi.sta.isconnected():
pass
time.sleep(5)
if iotstate == True and my_wifi.sta.isconnected():
while True:
time.sleep(2)
if iotrece == "p1add":
historyp1s = p1score
p1score = p1score + 1
time.sleep(1)
displayupdate()
if iotrece == "p2add":
historyp2s = p2score
p2score = p2score + 1
time.sleep(1)
displayupdate()
if iotrece == "p1red":
# 不形成负数形式分数
if p1score != 0:
p1score = p1score + -1
displayupdate()
# 设定发球者
if totallscore == 0:
sever = 3
severhelp = severhelp + 1
displayupdate()
if iotrece == "p2red":
# 不形成负数形式分数
if p1score != 0:
p1score = p1score + -1
displayupdate()
# 设定发球者
if totallscore == 0:
sever = 4
severhelp = severhelp + 1
displayupdate()
if iotrece == "reset":
p1score = 0
p2score = 0
totallscore = 0
severhelp = 1
sever = 0
oled.fill(0)
oled.show()
time.sleep(1)
iotrece = ""
time.sleep(5)
Mind+
由于我对C语言不够了解,所以在C语言上使用IOT有待大家探索,目前我只会用图形(积木)编写IOT服务。
在资源包里没有支持IOT的Mind+掌控板程序
咳咳,图片有限使用
这样程序就完成了
来看一下效果(无联网实验)
mpython X(mpython)
在视频的某个阶段
计分器套装使用