Approved content

The content below is provided by a partner.

stemhub/pxt-StemhubCity 0.1.5 GitHub

Stemhub City

An Extension for Stemhub Smart City and Smart Home.

Stemhub City is an educational kit for students to understand the concept of how smart city and smart home works. Teacher can teach students how to use sensors (human sensor, raindrop sensor, motion sensor) with micro:bit to build intelligent city.

icon

For more information, please visit: https://www.stemeshop.com/product-page/smart-city-%E6%99%BA%E8%83%BD%E5%AE%B6%E5%B1%85%E7%B3%BB%E7%B5%B1%E5%AD%B8%E7%BF%92%E5%A5%97%E8%A3%9D

Code Examples

Turning Servo

stemhubCity.servo(90, AnalogPin.P0)

Read sound sensor

let sound = stemhubCity.read_sound_sensor(AnalogPin.P0)

Control traffic light

let trafficLight = stemhubCity.traffic_light_setting(DigitalPin.P0, DigitalPin.P1, DigitalPin.P2)
basic.forever(function () {
    trafficLight.traffic_light_control(true, false, false)
    basic.pause(1000)
    trafficLight.traffic_light_control(false, true, false)
    basic.pause(1000)
    trafficLight.traffic_light_control(false, false, true)
    basic.pause(1000)
})

Control color led

let colorLED = stemhubCity.color_led_setting(AnalogPin.P0, AnalogPin.P1, AnalogPin.P2)
colorLED.color_led_control(1023, 500, 0)

Turn on white LED when motion detected

basic.forever(function () {
    if (stemhubCity.read_motion_sensor(AnalogPin.P0)) {
        stemhubCity.turn_white_led(1023, AnalogPin.P2)
        basic.pause(1000)
        stemhubCity.turn_white_led(0, AnalogPin.P2)
    }
})

Read Ultrasonic

let distance = stemhubCity.read_distance_sensor(stemhubCity.DistanceUnit.Centimeters, DigitalPin.P15, DigitalPin.P16)

Turn on fan if keypad key “1” is pressed

basic.forever(function () {
    if (stemhubCity.readKeyPad(DigitalPin.P0, DigitalPin.P1) == "1") {
        stemhubCity.FanControl(stemhubCity.FanState.On, DigitalPin.P14, DigitalPin.P15)
    }
})

Use OLED screen to display string

stemhubCity.OLED.init(128, 64)
basic.forever(function () {
    stemhubCity.OLED.writeStringNewLine("hi")
    basic.pause(500)
    stemhubCity.OLED.writeStringNewLine(":)")
    basic.pause(500)
    stemhubCity.OLED.clear()
})

Supported targets

for PXT/microbit

License

MIT

stemhubCity=github:stemhub/pxt-StemhubCity#v0.1.5