{"id":352,"date":"2026-04-01T19:06:24","date_gmt":"2026-04-01T17:06:24","guid":{"rendered":"https:\/\/yb-isn.fr\/2025\/nsi\/?p=352"},"modified":"2026-04-02T08:36:33","modified_gmt":"2026-04-02T06:36:33","slug":"33-le-retour-de-pacman","status":"publish","type":"post","link":"https:\/\/yb-isn.fr\/2025\/nsi\/2026\/04\/01\/33-le-retour-de-pacman\/","title":{"rendered":"33-Le retour de pacman"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\"><strong>Objectif : utiliser des capteurs et actionneurs pour transformer la carte microbit en manette pour votre jeu.<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">La carte microbit est reli\u00e9e au pc via le port usb. Il faut pour cela trouver le num\u00e9ro du port s\u00e9rie com du pc pour le renseigner dans le programme \u00e0 ex\u00e9cuter dans thonny.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-background has-link-color wp-elements-cf896911083c824db1c6bb75720887b0 wp-block-paragraph\" style=\"background:linear-gradient(135deg,rgb(216,244,179) 0%,rgb(17,184,81) 100%)\">1) Le capteur d&rsquo;acc\u00e9l\u00e9ration pour d\u00e9tecter l&rsquo;inclinaison de la carte dans le plan<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Utiliser l&rsquo;\u00e9diteur microbit de capytale pour communiquer avec la carte et obtenir le num\u00e9ro du port s\u00e9rie.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/capytale2.ac-paris.fr\/web\/c\/fe18-10453811\">https:\/\/capytale2.ac-paris.fr\/web\/c\/fe18-10453811<\/a><\/p>\n\n\n\n<div class=\"wp-block-esab-accordion esab-gigcv3h3\" data-mode=\"individual\" data-close=\"true\"><div class=\"esab__container\">\n<div class=\"wp-block-esab-accordion-child\"><div class=\"esab__head\" role=\"button\" aria-expanded=\"false\"><div class=\"esab__heading_txt\"><p class=\"esab__heading_tag\">code python pour le pc<\/p><\/div><div class=\"esab__icon\"><div class=\"esab__collapse\"> <svg version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\"><path fill-rule=\"evenodd\" d=\"m3.5 20.5c-4.7-4.7-4.7-12.3 0-17 4.7-4.7 12.3-4.7 17 0 4.6 4.7 4.6 12.3 0 17-4.7 4.6-12.3 4.6-17 0zm0.9-0.9c4.2 4.2 11 4.2 15.2 0 4.2-4.2 4.2-11 0-15.2-4.2-4.3-11-4.3-15.2 0-4.3 4.2-4.3 11 0 15.2z\"><\/path><path d=\"m11.4 15.9v-3.3h-3.3c-0.3 0-0.6-0.3-0.6-0.6 0-0.4 0.3-0.6 0.6-0.6h3.3v-3.3c0-0.3 0.3-0.6 0.6-0.6 0.3 0 0.6 0.3 0.6 0.6v3.3h3.3c0.3 0 0.6 0.2 0.6 0.6q0 0.2-0.2 0.4-0.2 0.2-0.4 0.2h-3.3v3.3q0 0.2-0.2 0.4-0.2 0.2-0.4 0.2c-0.4 0-0.6-0.3-0.6-0.6z\"><\/path><\/svg> <\/div><div class=\"esab__expand\"> <svg version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\"><path fill-rule=\"evenodd\" d=\"m12 24c-6.6 0-12-5.4-12-12 0-6.6 5.4-12 12-12 6.6 0 12 5.4 12 12 0 6.6-5.4 12-12 12zm10.6-12c0-5.9-4.7-10.6-10.6-10.6-5.9 0-10.6 4.7-10.6 10.6 0 5.9 4.7 10.6 10.6 10.6 5.9 0 10.6-4.7 10.6-10.6z\"><\/path><path d=\"m5.6 11.3h12.8v1.4h-12.8z\"><\/path><\/svg> <\/div><\/div><\/div><div class=\"esab__body\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame\n\nimport serial\n\npygame.init()\n\nLARGEUR, HAUTEUR = 800, 500\necran = pygame.display.set_mode((LARGEUR, HAUTEUR))\npygame.display.set_caption(\"Pacman pilot\u00e9 par micro:bit\")\nhorloge = pygame.time.Clock()\n\nrectangle = pygame.Rect(0, 0, 80, 60)\nrectangle.center = (LARGEUR \/\/ 2, HAUTEUR \/\/ 2)\n\nvitesse = 280.0\n\n# \u00c0 adapter selon votre machine :\n# Windows : \"COM3\", \"COM4\", ...\n# Linux   : \"\/dev\/ttyACM0\"\n# macOS   : \"\/dev\/cu.usbmodem...\"\nPORT = \"COM11\"\nBAUDRATE = 115200\n\nser = serial.Serial(PORT, BAUDRATE, timeout=0.02)\n\ndx, dy = 0, 0\nen_cours = True\n\nwhile en_cours:\n    dt = horloge.tick(60) \/ 1000.0\n\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            en_cours = False\n        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:\n            en_cours = False\n\n    # lecture des donn\u00e9es venant de la micro:bit\n    if ser.in_waiting:\n        try:\n            ligne = ser.readline().decode(\"utf-8\", errors=\"ignore\").strip()\n            if \";\" in ligne:\n                sx, sy = ligne.split(\";\")\n                dx = int(sx)\n                dy = int(sy)\n        except:\n            pass\n\n    rectangle.x += int(dx * vitesse * dt)\n    rectangle.y += int(dy * vitesse * dt)\n\n    rectangle.clamp_ip(pygame.Rect(0, 0, LARGEUR, HAUTEUR))\n\n    ecran.fill((20, 20, 30))\n    pygame.draw.rect(ecran, (80, 140, 255), rectangle, border_radius=10)\n    pygame.display.flip()\n\nser.close()\npygame.quit()\n\n\n<\/pre>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-background has-link-color wp-elements-f2b32e866baba1e26d10a07c373cb1df wp-block-paragraph\" style=\"background:linear-gradient(135deg,rgb(216,244,179) 0%,rgb(17,184,81) 100%)\">2) Modification des couleurs avec les boutons A et B<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/capytale2.ac-paris.fr\/web\/c\/c2a1-10453917\">https:\/\/capytale2.ac-paris.fr\/web\/c\/c2a1-10453917<\/a><\/p>\n\n\n\n<div class=\"wp-block-esab-accordion esab-p1kmiguy\" data-mode=\"individual\" data-close=\"true\"><div class=\"esab__container\">\n<div class=\"wp-block-esab-accordion-child\"><div class=\"esab__head\" role=\"button\" aria-expanded=\"false\"><div class=\"esab__heading_txt\"><p class=\"esab__heading_tag\">PC<\/p><\/div><div class=\"esab__icon\"><div class=\"esab__collapse\"> <svg version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\"><path fill-rule=\"evenodd\" d=\"m3.5 20.5c-4.7-4.7-4.7-12.3 0-17 4.7-4.7 12.3-4.7 17 0 4.6 4.7 4.6 12.3 0 17-4.7 4.6-12.3 4.6-17 0zm0.9-0.9c4.2 4.2 11 4.2 15.2 0 4.2-4.2 4.2-11 0-15.2-4.2-4.3-11-4.3-15.2 0-4.3 4.2-4.3 11 0 15.2z\"><\/path><path d=\"m11.4 15.9v-3.3h-3.3c-0.3 0-0.6-0.3-0.6-0.6 0-0.4 0.3-0.6 0.6-0.6h3.3v-3.3c0-0.3 0.3-0.6 0.6-0.6 0.3 0 0.6 0.3 0.6 0.6v3.3h3.3c0.3 0 0.6 0.2 0.6 0.6q0 0.2-0.2 0.4-0.2 0.2-0.4 0.2h-3.3v3.3q0 0.2-0.2 0.4-0.2 0.2-0.4 0.2c-0.4 0-0.6-0.3-0.6-0.6z\"><\/path><\/svg> <\/div><div class=\"esab__expand\"> <svg version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\"><path fill-rule=\"evenodd\" d=\"m12 24c-6.6 0-12-5.4-12-12 0-6.6 5.4-12 12-12 6.6 0 12 5.4 12 12 0 6.6-5.4 12-12 12zm10.6-12c0-5.9-4.7-10.6-10.6-10.6-5.9 0-10.6 4.7-10.6 10.6 0 5.9 4.7 10.6 10.6 10.6 5.9 0 10.6-4.7 10.6-10.6z\"><\/path><path d=\"m5.6 11.3h12.8v1.4h-12.8z\"><\/path><\/svg> <\/div><\/div><\/div><div class=\"esab__body\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame\npygame.init()\nimport serial\n\npygame.init()\n\nLARGEUR, HAUTEUR = 800, 500\necran = pygame.display.set_mode((LARGEUR, HAUTEUR))\npygame.display.set_caption(\"Rectangle pilot\u00e9 par micro:bit\")\nhorloge = pygame.time.Clock()\n\nrectangle = pygame.Rect(0, 0, 80, 60)\nrectangle.center = (LARGEUR \/\/ 2, HAUTEUR \/\/ 2)\n\nvitesse = 280.0\n\nPORT = \"COM11\"          # \u00e0 adapter\nBAUDRATE = 115200\n\nser = serial.Serial(PORT, BAUDRATE, timeout=0.02)\n\ndx, dy = 0, 0\ncouleur = (80, 140, 255)   # bleu initial\n\nen_cours = True\nwhile en_cours:\n    dt = horloge.tick(60) \/ 1000.0\n\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            en_cours = False\n        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:\n            en_cours = False\n\n    if ser.in_waiting:\n        try:\n            ligne = ser.readline().decode(\"utf-8\", errors=\"ignore\").strip()\n            if ligne:\n                print(ligne)   # debug\n\n            morceaux = ligne.split(\";\")\n            if len(morceaux) == 4:\n                sx, sy, sa, sb = morceaux\n                dx = int(sx)\n                dy = int(sy)\n                a = int(sa)\n                b = int(sb)\n\n                # la couleur change et reste m\u00e9moris\u00e9e\n                if a == 1 and b == 1:\n                    couleur = (255, 255, 0)   # jaune\n                elif a == 1:\n                    couleur = (255, 0, 0)     # rouge\n                elif b == 1:\n                    couleur = (0, 255, 0)     # vert\n\n        except Exception as e:\n            print(\"Erreur lecture s\u00e9rie :\", e)\n\n    rectangle.x += int(dx * vitesse * dt)\n    rectangle.y += int(dy * vitesse * dt)\n\n    rectangle.clamp_ip(pygame.Rect(0, 0, LARGEUR, HAUTEUR))\n\n    ecran.fill((20, 20, 30))\n    pygame.draw.rect(ecran, couleur, rectangle, border_radius=10)\n    pygame.display.flip()\n\nser.close()\npygame.quit()\n\n<\/pre>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-esab-accordion-child\"><div class=\"esab__head\" role=\"button\" aria-expanded=\"false\"><div class=\"esab__heading_txt\"><p class=\"esab__heading_tag\"><\/p><\/div><div class=\"esab__icon\"><div class=\"esab__collapse\"> <svg version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\"><path fill-rule=\"evenodd\" d=\"m3.5 20.5c-4.7-4.7-4.7-12.3 0-17 4.7-4.7 12.3-4.7 17 0 4.6 4.7 4.6 12.3 0 17-4.7 4.6-12.3 4.6-17 0zm0.9-0.9c4.2 4.2 11 4.2 15.2 0 4.2-4.2 4.2-11 0-15.2-4.2-4.3-11-4.3-15.2 0-4.3 4.2-4.3 11 0 15.2z\"><\/path><path d=\"m11.4 15.9v-3.3h-3.3c-0.3 0-0.6-0.3-0.6-0.6 0-0.4 0.3-0.6 0.6-0.6h3.3v-3.3c0-0.3 0.3-0.6 0.6-0.6 0.3 0 0.6 0.3 0.6 0.6v3.3h3.3c0.3 0 0.6 0.2 0.6 0.6q0 0.2-0.2 0.4-0.2 0.2-0.4 0.2h-3.3v3.3q0 0.2-0.2 0.4-0.2 0.2-0.4 0.2c-0.4 0-0.6-0.3-0.6-0.6z\"><\/path><\/svg> <\/div><div class=\"esab__expand\"> <svg version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\"><path fill-rule=\"evenodd\" d=\"m12 24c-6.6 0-12-5.4-12-12 0-6.6 5.4-12 12-12 6.6 0 12 5.4 12 12 0 6.6-5.4 12-12 12zm10.6-12c0-5.9-4.7-10.6-10.6-10.6-5.9 0-10.6 4.7-10.6 10.6 0 5.9 4.7 10.6 10.6 10.6 5.9 0 10.6-4.7 10.6-10.6z\"><\/path><path d=\"m5.6 11.3h12.8v1.4h-12.8z\"><\/path><\/svg> <\/div><\/div><\/div><div class=\"esab__body\">\n<p class=\"wp-block-paragraph\"><\/p>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Objectif : utiliser des capteurs et actionneurs pour transformer la carte microbit en manette pour votre jeu. La carte microbit [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-352","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"_links":{"self":[{"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/comments?post=352"}],"version-history":[{"count":12,"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/posts\/352\/revisions\/367"}],"wp:attachment":[{"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/media?parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/categories?post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yb-isn.fr\/2025\/nsi\/wp-json\/wp\/v2\/tags?post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}