Funpack10:Kitronik ARCADE游戏手柄-摩斯密码练习器
基于Kitronik ARCADE游戏手柄的摩斯密码练习器,实现摩斯密码的加密解密功能。
标签
嵌入式系统
Funpack10
ARCADE
摩斯码
shark_xin
更新2021-08-31
824

一、游戏板介绍

Kitronik ARCADE是一款专门设计用于运行复古街机游戏的平台 - 来自英国的Kitronik公司专为创客教育市场推出的Kitronik Arcade,搭配微软MakeCode Arcade编辑器一起使用。Kitronik Arcade功能齐全,符合人体工程学设计,舒适易用。具有全彩色 LCD 宽视角屏幕、用于音频反馈的压电发声器、用于触觉反馈的振动电机、6 个游戏玩家输入按钮、一个菜单按钮、一个重置按钮和一个开/关开关。完美游戏体验所需的一切。还具有软件音量控制、一个 USB 编程端口和 2 个为专家级用户提供的扩展端口。

ARCADE 可以由 3xAA 电池或通过微型 USB 连接器供电,电池座位于 PCB 的背面。三个电池座的位置还可以用作手柄,在游戏时提供最大的舒适度和控制力。

而对于高级用户,我们有2个扩展口和一个调试口。扩展端口可让您直接访问微处理器引脚,调试端口可让您自定义引导加载程序代码。

二、功能介绍

这是一个摩斯密码练习器,一共有两种模式:

解密模式:LCD屏上随机出现一个字符,敲出对应的组合(3-5个字符即可),正确时,蜂鸣器响;错误时,震动马达发出振动 

加密模式:敲击按键,识别出按键组合对应的字符,在屏幕上打出自己的id。

功能按键:SWA为点,SWB为横,上键加密解密功能键,下键模式切换按键,左键明文退格,右键密文退格。

   Fko_CqzjpDmiCLh2CYbxHvlkdVvL

三、代码片段及说明

1.先定义三个角色对象,并显示在屏幕上

baby = sprites.create(img("""
            . . . . . . f f f f . . . . . .
                    . . . . f f f 2 2 f f f . . . .
                    . . . f f f 2 2 2 2 f f f . . .
                    . . f f f e e e e e e f f f . .
                    . . f f e 2 2 2 2 2 2 e e f . .
                    . . f e 2 f f f f f f 2 e f . .
                    . . f f f f e e e e f f f f . .
                    . f f e f b f 4 4 f b f e f f .
                    . f e e 4 1 f d d f 1 4 e e f .
                    . . f e e d d d d d d e e f . .
                    . . . f e e 4 4 4 4 e e f . . .
                    . . e 4 f 2 2 2 2 2 2 f 4 e . .
                    . . 4 d f 2 2 2 2 2 2 f d 4 . .
                    . . 4 4 f 4 4 5 5 4 4 f 4 4 . .
                    . . . . . f f f f f f . . . . .
                    . . . . . f f . . f f . . . . .
        """),
        SpriteKind.player)
strawberry = sprites.create(img("""
            . . . . . . . 6 . . . . . . . .
                    . . . . . . 8 6 6 . . . 6 8 . .
                    . . . e e e 8 8 6 6 . 6 7 8 . .
                    . . e 2 2 2 2 e 8 6 6 7 6 . . .
                    . e 2 2 4 4 2 7 7 7 7 7 8 6 . .
                    . e 2 4 4 2 6 7 7 7 6 7 6 8 8 .
                    e 2 4 5 2 2 6 7 7 6 2 7 7 6 . .
                    e 2 4 4 2 2 6 7 6 2 2 6 7 7 6 .
                    e 2 4 2 2 2 6 6 2 2 2 e 7 7 6 .
                    e 2 4 2 2 4 2 2 2 4 2 2 e 7 6 .
                    e 2 4 2 2 2 2 2 2 2 2 2 e c 6 .
                    e 2 2 2 2 2 2 2 4 e 2 e e c . .
                    e e 2 e 2 2 4 2 2 e e e c . . .
                    e e e e 2 e 2 2 e e e c . . . .
                    e e e 2 e e c e c c c . . . . .
                    . c c c c c c c . . . . . . . .
        """),
        SpriteKind.player)
tree_content = sprites.create(img("""
            ......cc66......
                    .....c6576c.....
                    ....c677576c....
                    ....cc677666....
                    ...cc6c6667cc...
                    ..6c666777cc6c..
                    ..c76666766776..
                    ..c6777777776c..
                    ..cc67777776cc..
                    .c67cc76676676c.
                    .c777666667777c.
                    .c6777777777766.
                    .cc7767776776666
                    c676cc6766666776
                    c777766666677776
                    cc7777777777776c
                    .c676777677767c.
                    ..cc667666766c..
                    ...ccc6c66ccc...
                    .....cccccc.....
                    .......ee.......
                    ......eeee......
                    .....eeeeee.....
                    .......ee.......
        """),
        SpriteKind.player)

2.定义三个角色对象的位置

def on_forever():
    global baby, strawberry, tree_content
    tree_content.set_position(76, 40)
    baby.set_position(127, 95)
    strawberry.set_position(28, 95)
forever(on_forever)

3.定义上键功能

def on_up_pressed():
    global output_word,input_key,tree_display,A,output_key
    if A ==0: #加密判断
        try:
            output_word = mos_word[mos_key.index(input_key)]
            if mos_key.index(input_key) == -1:
                output_word = "error"
                controller.vibrate(500)
            strawberry.say(output_word,1000)
        except:
            strawberry.say("error")
            controller.vibrate(500)
        if output_word != "error" and output_word != "":
            tree_display = tree_display + output_word
        tree_content.say(tree_display)
    if A == 1: #解密判断
        output_key = mos_key[mos_word.index(output_word)]
        if output_key == input_key:
            tree_content.say("True")
            music.power_up.play()
            #print(input_key)
            output_word = mos_word._pick_random()
            strawberry.say(output_word)
        elif output_key != input_key:
            tree_content.say("ERROR")
            controller.vibrate(1000)
controller.up.on_event(ControllerButtonEvent.PRESSED, on_up_pressed)

4.定义下键功能

def on_down_pressed():
    global A,output_word
    A =A+1
    if A == 1:
        output_word = mos_word._pick_random()
        strawberry.say(output_word)
        if tree_display != "":
            tree_display = ""
            tree_content.say("解密模式",1000)
        else:
            tree_content.say("解密模式",1000)
    elif A == 2:
        tree_content.say("加密模式",1000)
        A = 0
        output_word = ""
        strawberry.say(output_word)
controller.down.on_event(ControllerButtonEvent.PRESSED, on_down_pressed)

5.定义左键功能

def on_left_pressed():
    global tree_display
    tree_display = tree_display[:-1]
    tree_content.say(tree_display)
    # if tree_display == "":
        #     tree_content.say("null",1000)
    # if tree_display == "":
        #     tree_display = "null"
controller.left.on_event(ControllerButtonEvent.PRESSED, on_left_pressed)

6.定义右键功能

def on_right_pressed():
    global input_key,num
    input_key = input_key[:-1]
    if len(input_key) >= 6:
        num = num+1
        if num == 5:
            input_key = ""
            num = 0
    baby.say(input_key)
controller.right.on_event(ControllerButtonEvent.PRESSED, on_right_pressed)

6.a键功能

def on_a_pressed():
    global input_key
    input_key = input_key + "."
    baby.say(input_key)
    controller.vibrate(100)
    music.jump_up.play()
controller.A.on_event(ControllerButtonEvent.PRESSED, on_a_pressed)

7.b键功能

def on_b_pressed():
    global input_key
    input_key = input_key + "-"
    baby.say(input_key)
    controller.vibrate(100)
    music.jump_down.play()
controller.B.on_event(ControllerButtonEvent.PRESSED, on_b_pressed)

四、功能演示

1.开机界面:

FvMHZpGWBEmoi3P_dP6AQ8iV37_r

2.解密模式界面:

Ftu_NppW-aodYvRtp0v3mvdSu6yW

3.加密模式界面:

FjQ241cu26fzuK0lrK9yUVyhBeAp

4.加密模式正确加密:

FmtaLIv-IiOP0u1LFrif1N2FU7Vr

5.打出自己的ID:

FtSnZFkxD_Copm6oboZv8oshecji

6.解密模式正确,蜂鸣器发出声音

FiyqZV17nzPgjcqNQBUJtQyOGpPA

7.解密模式错误,震动马达发出震动:

FkRtrx_vsC-Zt1x2Uc_65m3Rvjoe

 

五、心得体会

Kitronik ARCADE是一款功能丰富的游戏编程手柄,可以有非常多的功能可做,只是这个python的编辑器很拉胯,功能不是很丰富,可以支持第三方的IDE就更好了。

 

附件下载
莫斯密码器手柄.md
团队介绍
评论
0 / 100
查看更多
目录
硬禾服务号
关注最新动态
0512-67862536
info@eetree.cn
江苏省苏州市苏州工业园区新平街388号腾飞创新园A2幢815室
苏州硬禾信息科技有限公司
Copyright © 2023 苏州硬禾信息科技有限公司 All Rights Reserved 苏ICP备19040198号