Menú
It all started with a simple voice-activated light, and then every corner of my house began to get "smart," as if touched by magic.
1 let noise = 0 2 let light2 = 0 3 led.enable(false) 4 basic.forever(function () { 5 light2 = smarthome.ReadLightIntensity(AnalogPin.P3) 6 if (light2 < 50) { 7 noise = smarthome.ReadNoise(AnalogPin.P2) 8 if (noise > 70) { 9 neopixel.create(DigitalPin.P1, 1, NeoPixelMode.RGB).showColor(neopixel.colors(NeoPixelColors.White)) 10 basic.pause(10000) 11 neopixel.create(DigitalPin.P1, 1, NeoPixelMode.RGB).showColor(neopixel.colors(NeoPixelColors.Black)) 12 } 13 } 14 })
1 let temp = 0 2 OLED.init(128, 64) 3 basic.forever(function () { 4 temp = smarthome.ReadTemperature(TMP36Type.TMP36_temperature_C, AnalogPin.P1) 5 OLED.clear() 6 OLED.writeString("Temperature:") 7 OLED.writeNum(temp) 8 if (temp > 30) { 9 music.startMelody(music.builtInMelody(Melodies.BaDing), MelodyOptions.Once) 10 pins.digitalWritePin(DigitalPin.P2, 1) 11 basic.pause(5000) 12 pins.digitalWritePin(DigitalPin.P2, 0) 13 basic.pause(500) 14 } else { 15 pins.digitalWritePin(DigitalPin.P2, 0) 16 } 17 })
1 pins.setPull(DigitalPin.P2, PinPullMode.PullUp) 2 pins.servoWritePin(AnalogPin.P7, 180) 3 let door = -1 4 basic.forever(function () { 5 if (pins.digitalReadPin(DigitalPin.P2) == 0) { 6 door = door * -1 7 if (door == 1) { 8 neopixel.create(DigitalPin.P1, 1, NeoPixelMode.RGB).range(0, 1).showColor(neopixel.colors(NeoPixelColors.White)) 9 pins.servoWritePin(AnalogPin.P7, 0) 10 basic.pause(2000) 11 } else { 12 pins.servoWritePin(AnalogPin.P7, 180) 13 basic.pause(2000) 14 neopixel.create(DigitalPin.P1, 1, NeoPixelMode.RGB).range(0, 1).showColor(neopixel.colors(NeoPixelColors.Black)) 15 } 16 } 17 })
1 let noise = 0 2 pins.servoWritePin(AnalogPin.P1, 0) 3 basic.forever(function () { 4 noise = smarthome.ReadNoise(AnalogPin.P10) 5 if (noise > 70) { 6 pins.servoWritePin(AnalogPin.P1, 0) 7 basic.pause(1000) 8 } else { 9 pins.servoWritePin(AnalogPin.P1, 100) 10 basic.pause(1000) 11 } 12 })
1 basic.forever(function () { 2 if (pins.analogReadPin(AnalogReadWritePin.P2) > 500) { 3 music.startMelody(music.builtInMelody(Melodies.BaDing), MelodyOptions.Once) 4 pins.digitalWritePin(DigitalPin.P1, 1) 5 basic.pause(10000) 6 } else { 7 pins.digitalWritePin(DigitalPin.P1, 0) 8 basic.pause(10000) 9 } 10 })
1 OLED.init(128, 64) 2 smarthome.crashSensorSetup(DigitalPin.P1) 3 basic.forever(function () { 4 if (smarthome.crashSensor()) { 5 OLED.writeStringNewLine("your house is safe") 6 } else { 7 OLED.writeStringNewLine("Intruder Detected") 8 music.startMelody(music.builtInMelody(Melodies.BaDing), MelodyOptions.Once) 9 } 10 })
1 OLED.init(128, 64) 2 let strip = neopixel.create(DigitalPin.P2, 1, NeoPixelMode.RGB) 3 smarthome.crashSensorSetup(DigitalPin.P1) 4 basic.forever(function () { 5 if (smarthome.crashSensor()) { 6 OLED.writeStringNewLine("your treasure is safe") 7 strip.showColor(neopixel.colors(NeoPixelColors.Green)) 8 } else { 9 OLED.writeStringNewLine("your treasure not safe") 10 strip.showColor(neopixel.colors(NeoPixelColors.Red)) 11 } 12 })
1 let noise = 0 2 led.enable(false) 3 pins.setPull(DigitalPin.P2, PinPullMode.PullUp) 4 OLED.init(128, 64) 5 pins.servoWritePin(AnalogPin.P8, 180) 6 let open = false 7 basic.forever(function () { 8 noise = smarthome.ReadNoise(AnalogPin.P1) 9 if (noise > 70) { 10 OLED.clear() 11 OLED.writeString("somebody out") 12 basic.pause(1000) 13 } 14 if (pins.digitalReadPin(DigitalPin.P2) == 0) { 15 open = !(false) 16 if (open == true) { 17 pins.servoWritePin(AnalogPin.P8, 0) 18 basic.pause(3000) 19 } 20 } else { 21 pins.servoWritePin(AnalogPin.P8, 180) 22 OLED.clear() 23 OLED.writeString("nobody") 24 basic.pause(1000) 25 } 26 })
1 let strip = neopixel.create(DigitalPin.P2, 24, NeoPixelMode.RGB) 2 basic.forever(function () { 3 basic.showIcon(IconNames.Happy) 4 if (smarthome.ReadNoise(AnalogPin.P1) > 30) { 5 strip.showColor(neopixel.colors(NeoPixelColors.Red)) 6 basic.pause(100) 7 if (smarthome.ReadNoise(AnalogPin.P1) > 40) { 8 strip.showColor(neopixel.colors(NeoPixelColors.Orange)) 9 basic.pause(100) 10 if (smarthome.ReadNoise(AnalogPin.P1) > 50) { 11 strip.showColor(neopixel.colors(NeoPixelColors.Yellow)) 12 basic.pause(100) 13 // ...more color levels} 14 } 15 } 16 } 17 })
1 OLED.init(128, 64) 2 basic.showIcon(IconNames.Happy) 3 OLED.writeStringNewLine("welcome to the game") 4 basic.pause(2000) 5 basic.forever(function () { 6 if (smarthome.ReadNoise(AnalogPin.P1) > 30) { 7 basic.showLeds(` 8 . . . . . 9 . . . . . 10 . . . . . 11 . . . . . 12 # # # # # 13 `) 14 OLED.clear() 15 OLED.writeNumNewLine(1) 16 basic.pause(100) 17 } 18 // more levels... 19 })
1 let readings = 0 2 let elec = 0 3 let stddev = 0 4 OLED.init(128, 64) 5 OLED.writeStringNewLine("Please place your fingers on the sensor.") 6 basic.pause(2000) 7 let std = Math.sqrt(stddev / 30) 8 let list: number[] = [] 9 for (let index = 0; index < 30; index++) { 10 list.push(pins.analogReadPin(AnalogReadWritePin.P1)) 11 elec += pins.analogReadPin(AnalogReadWritePin.P1) 12 basic.pause(1000) 13 } 14 // more code...