zoukankan      html  css  js  c++  java
  • Micro:bit第二集——温控与风扇

    let average = 0
    let sum = 0
    let min = 0
    let max = 0
    let line = 0
    let 转速 = 0
    let 温度 = 0
    input.onButtonPressed(Button.A, function () {
        basic.pause(2000)
        OLED12864_I2C.showNumber(0, line, line * 2)
        OLED12864_I2C.showString(2, line, "sec")
        OLED12864_I2C.showNumber(7, line, 温度)
        OLED12864_I2C.showNumber(11, line, 转速)
        line += 1
        sum = 温度
        max = 温度
        min = 温度
        for (let i = 0; i < 4; i++) {
            basic.pause(2000)
            OLED12864_I2C.showNumber(0, line, line * 2)
            OLED12864_I2C.showString(2, line, "sec")
            OLED12864_I2C.showNumber(7, line, 温度)
            OLED12864_I2C.showNumber(11, line, 转速)
            line += 1
            sum = sum + 温度
            if (温度 >= max) {
                max = 温度
            }
            if (温度 <= min) {
                min = 温度
            }
        }
        average = Math.floor(sum / 5)
        OLED12864_I2C.showString(0, line, "max")
        OLED12864_I2C.showNumber(5, line, max)
        OLED12864_I2C.showString(8, line, "min")
        OLED12864_I2C.showNumber(11, line, min)
        OLED12864_I2C.showString(0, line + 1, "average")
        OLED12864_I2C.showNumber(9, line + 1, average)
    })
    input.onButtonPressed(Button.B, function () {
        OLED12864_I2C.init()
        line = 1
        max = 0
        min = 99
        sum = 0
        average = 0
        OLED12864_I2C.showString(0, 0, "start")
        OLED12864_I2C.showString(7, 0, "tem")
        OLED12864_I2C.showString(11, 0, "speed")
    })
    OLED12864_I2C.init()
    line = 1
    max = 0
    min = 99
    sum = 0
    average = 0
    OLED12864_I2C.showString(0, 0, "start")
    OLED12864_I2C.showString(7, 0, "tem")
    OLED12864_I2C.showString(11, 0, "speed")
    basic.forever(function () {
        温度 = input.temperature()
        转速 = 温度 * 5
        pins.analogWritePin(AnalogPin.P1, 转速)
    })
    

      今天给大家介绍microbit的温控与风扇,要求是

    1.每两秒测一次温度,十秒内测5次

    2.风扇转速按温度改变而改变

    3.计算每两秒的温度平均值,十秒的最大值,最小值

    上面是Javascript的源代码,大家可以到源软件里去转换成块状的看哦~

    (温馨提示:本次用的网站是ide.ithingedu.com,不是原来的!!!)

  • 相关阅读:
    算数基本定理与质因数分解
    质数的两种筛法
    质数及其判法
    二十二、Spring MVC与Structs2的区别总结
    二十一、MVC的WEB框架(Spring MVC)
    二十、MVC的WEB框架(Spring MVC)
    十九、Spring框架(注解方式测试)
    十八、Spring框架(AOP)
    十七、Spring框架(IOC/DI)
    创建型模式篇(建造者模式Builder Pattern)
  • 原文地址:https://www.cnblogs.com/lucasyy/p/13233012.html
Copyright © 2011-2022 走看看