Last summer I created some resources to use with Micro:bit/s for CPC and over the next few months and I will try and share the best bits with the kind permission of CPC.
This second one uses Micropython and a neopixel again. The neopixel is from this kit:
The picture below shows how the Micro:bit is set up, this time it has an added Storm Trooper :)
The code builds on from blog post 1:
This version uses the temperature of the CPU to determine which face is displayed and which colour light the neo pixel shows. There are two versions which have different ranges of the conditions of the CPU.
Version 1 code:
# Add your Python code here. E.g.
from microbit import *
import neopixel
np = neopixel.NeoPixel(pin0,1)
def Angry():
np[0] = (255,0,0)#Red
np.show()
display.show(Image.ANGRY)
sleep(3000)
np.clear()
def Happy():
np[0] = (0,255,0)#Green
np.show()
display.show(Image.HAPPY)
sleep(3000)
np.clear()
def Meh():
np[0] = (255,69,0)#Yellow
np.show()
display.show(Image.MEH)
sleep(3000)
np.clear()
while True:
temp = temperature()
if temp <= 27:#happy at body temp
Happy()
elif temp > 27 or temp <=29:#above body temp but ok
Meh()#ok
elif temp > 29 or temp <= 31:
Angry()
else:
display.show(Image.SKULL)#
from microbit import *
import neopixel
np = neopixel.NeoPixel(pin0,1)
def Angry():
np[0] = (255,0,0)#Red
np.show()
display.show(Image.ANGRY)
sleep(3000)
np.clear()
def Happy():
np[0] = (0,255,0)#Green
np.show()
display.show(Image.HAPPY)
sleep(3000)
np.clear()
def Meh():
np[0] = (255,69,0)#Yellow
np.show()
display.show(Image.MEH)
sleep(3000)
np.clear()
while True:
temp = temperature()
if temp <= 25:#happy at body temp
Meh()#ok / cool
elif temp >= 25 or temp <=50:#above body temp but ok
Happy()#ok / coo
elif temp > 50 or temp <= 75:#super hot
Angry()
No comments:
Post a Comment