boussole — Indique le nord

Ce programme indique le nord par une flèche. C’est une version moins élégante que celle proposée dans la documentation officielle, mais plus simplement compréhensible par des élèves débutants en informatique.

 1# Copyright 2019 Louis Paternault
 2#
 3# This file is part of Jouets.
 4#
 5# Jouets is free software: you can redistribute it and/or modify
 6# it under the terms of the GNU General Public License as published by
 7# the Free Software Foundation, either version 3 of the License, or
 8# (at your option) any later version.
 9#
10# Jouets is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with Jouets.  If not, see <http://www.gnu.org/licenses/>.
17
18"""Indique le nord par une flèche."""
19
20from microbit import *
21
22compass.calibrate()
23
24while True:
25    aiguille = compass.heading()
26
27    if aiguille < 22.5:
28        display.show(Image.ARROW_N)
29    elif aiguille < 67.5:
30        display.show(Image.ARROW_NW)
31    elif aiguille < 112.5:
32        display.show(Image.ARROW_W)
33    elif aiguille < 157.5:
34        display.show(Image.ARROW_SW)
35    elif aiguille < 202.5:
36        display.show(Image.ARROW_S)
37    elif aiguille < 247.5:
38        display.show(Image.ARROW_SE)
39    elif aiguille < 292.5:
40        display.show(Image.ARROW_E)
41    elif aiguille < 337.5:
42        display.show(Image.ARROW_NE)
43    else:
44        display.show(Image.ARROW_N)