[∇]
[Δ] BBC
micro:bit : Affichage d’un canard
* *
* * *
* * * * *
* * *
# Copyright (C) 2017-2018 cc-by-sa 4.0 License : SparkFun
# Version 2018-04-18 cc-by-sa 4.0 http://ModLibre.info
#
# SparkFun Electronics https://www.sparkfun.com/microbit
# https://learn.sparkfun.com/tutorials/sparkfun-inventors-kit-for-microbit-experiment-guide
# Experiment 0.1 : Display an image
#
# Circuit: None = Aucun (compatible with 4tronix Music:Box)
# 3 P0 4 5 6 7 P1 8 9 10 11 12 P2 13 14 15 16 17 3V 18 19 20 21 0V 22
# P0 P1 3V 0V
from microbit import *
while True:
display.show(Image.DUCK)
Simulations de l’écran du micro:bit
* *
* * *
* * * * *
* * *
□ ■ ■ □ □
■ ■ ■ □ □
□ ■ ■ ■ ■
□ ■ ■ ■ □
[∇]
[Δ] Pyboard : Tableaux inspirés de Mondrian
# main.py -- put your code here!
#:Copyright (C) 2013-2018 MIT License : Nicholas H. TOLLERVEY...
# Ref: MicroPython-Hack-1LED
# http://wiki.mchobby.be/index.php?title=MicroPython-Hack-1LED
# Version 2018-09-07 MIT License : Jean.Thiery@ModLibre.info
#
# NB: Exemple de MicroPython pour le Pyboard
import pyb
from pyb import Pin
import lcd160cr
from random import randint, choice, uniform
# Déclaration des broches
# pin_out = Pin('Y9', Pin.OUT_PP)
# pRed = pyb.Pin( RED_PIN, pyb.Pin.OUT_PP )
# pGreen = pyb.Pin( GREEN_PIN, pyb.Pin.OUT_PP )
# pBlue = pyb.Pin( BLUE_PIN, pyb.Pin.OUT_PP )
pyb.LED(1).on() # Red
pyb.LED(2).on() # Green
pyb.LED(3).on() # Yellow
pyb.LED(4).on() # Blue
# while True:
for i in range(4):
pyb.LED(1).toggle() # Red
pyb.delay(500)
pyb.LED(2).toggle() # Green
pyb.delay(500)
pyb.LED(3).toggle() # Yellow
pyb.delay(500)
pyb.LED(4).toggle() # Blue
pyb.delay(500)
# Attendre 1 secondes
pyb.delay( 1000 )
# Tout en noir (toutes les LEDs éteintes)
pyb.LED(1).off() # Red
pyb.LED(2).off() # Green
pyb.LED(3).off() # Yellow
pyb.LED(4).off() # Blue
lcd = lcd160cr.LCD160CR('X')
MAX_DEPTH = 4
RED = lcd.rgb(255, 0, 0)
YELLOW = lcd.rgb(255, 255, 0)
BLUE = lcd.rgb(0, 0, 255)
WHITE = lcd.rgb(255, 255, 255)
BLACK = lcd.rgb(0, 0, 0)
COLOURS = [RED, YELLOW, BLUE, WHITE, WHITE, WHITE]
class Node:
"""
Un noeud d'arborescence du sujet tableau Mondrian.
"""
def __init__(self, depth=0):
"""
Choix de la couleur, calcul de profondeur
et ajout de noeuds enfants si pas trop dense.
"""
self.colour = choice(COLOURS)
self.depth = depth + 1
self.children = []
if self.depth <= MAX_DEPTH:
self.direction = choice(['h', 'v'])
self.divide = uniform(0.1, 0.9)
self.children.append(Node(self.depth))
self.children.append(Node(self.depth))
def draw(self, x, y, w, h):
"""
Trace ce noeud et ses enfants x fois.
"""
lcd.set_pen(BLACK, self.colour)
lcd.rect(x, y, w, h)
if self.children:
if self.direction == 'h':
self.children[0].draw(x, y, int(w * self.divide), h)
self.children[1].draw(x + int(w * self.divide), y,
int(w * (1.0 - self.divide)), h)
else:
self.children[0].draw(x, y, w, int(h * self.divide))
self.children[1].draw(x, y + int(h * self.divide), w,
int(h * (1.0 - self.divide)))
while True:
# Produit un nouveau tableau Mondrian au bout de 4-8 sec.
tree = Node()
tree.draw(0, 0, lcd.w, lcd.h)
pyb.delay(randint(4000, 8000))