Things used in this project

Hardware components:
DFRobot BOSON starter kit for micro:bit
×1
Microbitheart
BBC micro:bit board
×1

Code

demo1.pyPython
from microbit import *
mode = [700, 900, 1023]
while True:
   for speed in mode:
      print(speed)
      pin8.write_analog(speed)
      sleep(1000) 
demo2.pyPython
from microbit import *
fan_switch = False
while True:
   if pin12.read_digital():
      fan_switch = not fan_switch
      print('ON' if fan_switch else 'OFF')
      pin8.write_digital(int(fan_switch))
      while pin12.read_digital():
         sleep(100)  
demo3.pyPython
from microbit import *
fan_switch = False
fan_mode = ["slow", "medium","fast"]
fan_power = [700, 900, 1023]
def fan_mode_switch(value):
   interval = int(1023/3)
   for i in range(3):
      if value >= i * interval and value < (i+1)*interval:
         break
   return fan_mode[i], fan_power[i]

previous_mode, power = fan_mode_switch(pin0.read_analog())

while True:
   if pin12.read_digital():
      fan_switch = not fan_switch
      print('Fan status: ' + ('ON' if fan_switch else 'OFF'))
      while pin12.read_digital():
         sleep(100)
   if fan_switch:
       mode, power = fan_mode_switch(pin0.read_analog())
       if mode is not previous_mode:
          previous_mode = mode
          print("Fan mode: ", mode)
          pin8.write_analog(power)
       else:
          previous_mode = 'OFF'
          pin8.write_analog(0)
       sleep(300) 

Credits

Ecddc9bf12bbd2c848d8b2e7757445e3
CAVEDU Education
10 projects • 9 followers
We provide tutorials of robotics, Arduino, Raspberry Pi and IoT topics. http://www.cavedu.com
Contact
Icon square orangewhite 120x120
DFRobot
7 projects • 31 followers
Contact
Photo
DFRobot Robotics
3 projects • 1 follower
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / LoginAbout BBC micro:bit