
"""


Auteur: anonyme

Interface: wb55

Nom du projet: main

Description: Nom du projet

Toolbox: vittascience

Mode: mixed

Blocks: <xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="ES5TtJ`3PH|gNu.c/bR,">lcd</variable><variable id="u*lu#X?Z3]ppk~$BD;q?">obstacle_pos</variable><variable id="x?*?f{^mw}QMR$#xm(P-">ecran_largeur</variable></variables><block type="call_expression" id="`A3$N}xLty~ZP:^~C.3K" x="0" y="0"><field name="NAME">machine</field><value name="chain"><block type="call_expression_editable_return" id="_oCzO%ohKtejFu*7M+)A"><mutation items="1"></mutation><field name="NAME">I2C</field><value name="items0"><block type="math_number" id=":YM|T(vIAwSpO?r{nPx7"><field name="NUM">1</field></block></value></block></value></block><block type="on_start" id="VnIwMr~E5D?yA$HNU:|y" x="20" y="20"><statement name="DO"><block type="text_comment" id="|6fMqrvMAp3?A]]WI{{F"><field name="TEXT"> deplacement obstacle</field><next><block type="text_comment" id="X$5HahR.JO1H1[!o();-"><field name="TEXT"> Initialisation de l'écran LCD via I2C</field><next><block type="variables_set" id=";I8h!Gc1cuNdY@XTM4zi"><field name="VAR" id="ES5TtJ`3PH|gNu.c/bR,">lcd</field><value name="VALUE"><block type="call_expression_editable_return" id="p[f|YNd|w2=v8zMLf6i_"><mutation items="1"></mutation><field name="NAME">LCD1602</field><value name="items0"><block type="keyword_argument" id="F5RDEE$S0%fF^10nV9WB"><field name="NAME">i2c</field></block></value></block></value><next><block type="text_comment" id="z/_n?vhj$WJIkxSjWs_J"><field name="TEXT"> Variables du jeu</field><next><block type="variables_set" id="n2J66Gndclnir7wss[f$"><field name="VAR" id="u*lu#X?Z3]ppk~$BD;q?">obstacle_pos</field><value name="VALUE"><block type="math_number" id="vps+A357Hg+,MerKU1bs"><field name="NUM">15</field></block></value><next><block type="variables_set" id="i#2`$gP.idY5?}!;z/}("><field name="VAR" id="x?*?f{^mw}QMR$#xm(P-">ecran_largeur</field><value name="VALUE"><block type="math_number" id="lg/Kqezl3lcaFWsJN$y."><field name="NUM">15</field></block></value><next><block type="text_comment" id="MCcYSG|8$asMPH2`K162"><field name="TEXT"> Largeur de l'afficheur (16 colonnes)</field><next><block type="text_comment" id="GQI;wVrOp[1{]NmZ_ZB^"><field name="TEXT"> Fonction pour afficher l'état du jeu</field><next><block type="text_comment" id="g!o|)0m{Jhke:N)HGw@o"><field name="TEXT"> Boucle du jeu</field></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block><block type="procedures_defnoreturn" id="#|7/^o}7{y%}IE-tI%oO" x="360" y="10"><mutation name="afficher_jeu"></mutation><field name="NAME">afficher_jeu</field><statement name="STACK"><block type="call_expression" id="yPI=E(PqudM#I[qyd):7"><field name="NAME">lcd</field><value name="chain"><block type="call_expression_editable_return" id="Hjg`a}2uX@yJs%#C,eV7"><field name="NAME">clear</field></block></value><next><block type="text_comment" id="[l`h*cx*(vUV9Y_8tZoR"><field name="TEXT"> Afficher l'obstacle</field><next><block type="call_expression" id=":Dwo2C{;#%lyP/e#rXzz"><field name="NAME">lcd</field><value name="chain"><block type="call_expression_editable_return" id="cNPBo0Dk{}qH{H96QaMu"><mutation items="2"></mutation><field name="NAME">setCursor</field><value name="items0"><block type="variables_get" id="wN0SXOK[GM=-)TA;1*sM"><field name="VAR" id="u*lu#X?Z3]ppk~$BD;q?">obstacle_pos</field></block></value><value name="items1"><block type="math_number" id=":7%c?g8.+k#{i@Lprbh~"><field name="NUM">1</field></block></value></block></value><next><block type="call_expression" id="P4wsOT]_{Yq|xvk1vHI["><field name="NAME">lcd</field><value name="chain"><block type="call_expression_editable_return" id="UpQ:{riGJir}cgFqM_l-"><mutation items="1"></mutation><field name="NAME">writeTxt</field><value name="items0"><block type="text" id="!JO%z`I~!fQ0sIiK^IJs"><field name="TEXT">&lt;</field></block></value></block></value><next><block type="text_comment" id="KGOi6c=l=X+r!eis#:`5"><field name="TEXT"> représente l'obstacle</field></block></next></block></next></block></next></block></next></block></statement></block><block type="forever" id=";8=uBHS0=$;9.Y5XmdSH" x="10" y="579"><statement name="DO"><block type="procedures_callnoreturn" id="o.m{0p3bqf~p7eLS+~+v"><mutation name="afficher_jeu"></mutation><next><block type="text_comment" id="ewK~~$-3Mv+[tiMA-89("><field name="TEXT"> Avancer l'obstacle de droite à gauche</field><next><block type="controls_if" id="Gx~q~|d)4}_Oft[h~hY/"><value name="IF0"><block type="logic_compare" id="o@!YepiFhB81F~?QcMD."><field name="OP">LT</field><value name="A"><block type="variables_get" id="@nc2cSmsf}s-*{J4-*#J"><field name="VAR" id="u*lu#X?Z3]ppk~$BD;q?">obstacle_pos</field></block></value><value name="B"><block type="math_number" id="#|N!l9RD|R2^wSzP[Vax"><field name="NUM">0</field></block></value></block></value><statement name="DO0"><block type="variables_set" id="vleiG^d@mE]/zqeRavg."><field name="VAR" id="u*lu#X?Z3]ppk~$BD;q?">obstacle_pos</field><value name="VALUE"><block type="math_arithmetic" id="8Rj6drBS4sVqac%c=+z*"><field name="OP">MINUS</field><value name="A"><block type="variables_get" id="-NOmG4Qw;+DqG{[mkCv:"><field name="VAR" id="x?*?f{^mw}QMR$#xm(P-">ecran_largeur</field></block></value><value name="B"><block type="math_number" id="{{Az}xt*5,:@ydG(^M@%"><field name="NUM">1</field></block></value></block></value></block></statement><next><block type="call_expression" id="=j!Y(g_piF`=THp#azU%"><field name="NAME">utime</field><value name="chain"><block type="call_expression_editable_return" id="eN!fd@K/va%ovjflrb|5"><mutation items="1"></mutation><field name="NAME">sleep_ms</field><value name="items0"><block type="math_number" id="|sPz7.u_lb8.UEPugM6["><field name="NUM">500</field></block></value></block></value><next><block type="text_comment" id="yqSF_F40Nu^i;twJf*aG"><field name="TEXT"> Délai pour la vitesse de déplacement de l'obstacle</field></block></next></block></next></block></next></block></next></block></statement></block></xml>

Projet généré par Vittascience.

Ce fichier contient le code textuel ainsi que le code blocs. Il peut être importé de nouveau

sur l'interface http://vittascience.com/wb55


"""

# deplacement obstacle

import machine
import utime
import pyb
from stm32_lcd_i2c import LCD1602

# Initialisation de l'écran LCD via I2C
lcd = LCD1602(i2c=machine.I2C(1))

# Variables du jeu
obstacle_pos = 15
ecran_largeur = 15  # Largeur de l'afficheur (16 colonnes)

# Fonction pour afficher l'état du jeu
def afficher_jeu():
    
    lcd.clear()
    
    # Afficher l'obstacle
    lcd.setCursor(obstacle_pos, 1)
    lcd.writeTxt('<')  # représente l'obstacle
  

# Boucle du jeu
while True:
    afficher_jeu()


    # Avancer l'obstacle de droite à gauche
    obstacle_pos -= 1
    if obstacle_pos < 0:  # Si l'obstacle quitte l'écran, il revient à droite
      obstacle_pos = ecran_largeur - 1
        
    utime.sleep_ms(500)  # Délai pour la vitesse de déplacement de l'obstacle