salem95
Messages postés1Date d'inscriptionmercredi 10 juillet 2013StatutMembreDernière intervention10 juillet 2013
-
10 juil. 2013 à 15:11
bonjour j ai un programme picaxe d un projey ' memosco' mais j n ai aucune ideé sur le language de ce programme ! est ce que vous pouvez m aider svp et merci!
'
' - JAUNE : Touches => A.1 Led => C.4
' - VERTE : Touches => A.2 Led => C.5
' - BLEUE : Touches => A.5 Led => C.6
' - BLANCHE : Touches => A.6 Led => C.7
' - ROUGE : Touches => A.7 Led => C.3
' - AFFICHEUR UNITES : Port B.0 à B.7
' - AFFICHEUR DIZAINES : Port D.0 à D.7
' - NIVEAU DE JEU (vitesse) : A.0 canal ADC0
' - SON : C.0
#picaxe 40X2 'Composant utilisé: PICAXE-40X2
#terminal off 'Pas de terminal sur PC
#no_data
#no_table
setfreq m8 'Fréquence de travail: 8MHz
dirsA=%00000000 'Ports A.0 à A.7 en entrée
dirsB=%11111111 'Ports B.0 à B.7 en sortie
dirsC=%11111111 'Ports C.0 à C.7 en sortie
dirsD=%11111111 'Ports D.0 à D.7 en sortie
let adcsetup = %0000000000000001 'Ligne A.0 en entrée ANA
'******** CONSTANTES ET VARIABLES *********************************************
'Constantes
symbol SON = C.0 'Sonorités sur la ligne C.0
symbol JAUNE = C.4 'Led jaune sur la ligne C.4
symbol VERT = C.5 'Led verte sur la ligne C.5
symbol BLEU = C.6 'Led bleue sur la ligne C.6
symbol BLANC = C.7 'Led blanche sur la ligne C.7
symbol ROUGE = C.3 'Led rouge sur la ligne C.3
'Variables WORD
symbol ALEATOIRE=w0 ' aléatoire de type "word"
'Variables BYTE
symbol DUREE=b11 'Durée de pause
symbol UNITE=b12 'Unités du nombre à afficher
symbol DIZAIN=b13 'Dizaines du nombre à afficher
symbol CHOIX=b14 'Note et Couleur choisie
symbol POSJEU=b15 'Position dans le jeu
symbol NOTE=b16 'Hauteur de la note
symbol CYCLE=b17 'Nombre de cycles en jeu
symbol COMPT1=b18 'Compteur numéro 1
symbol COMPT2=b19 'Compteur numéro 2
symbol COMPT3=b20 'Compteur numéro 3
symbol COMPT4=b21 'Compteur numéro 4
symbol VITESSE=b22 'Vitesse du jeu
symbol NIVEAU=b23 'Niveau de difficulté
symbol CHIFFRE=b24 'Chiffre à décoder
symbol NOMBRE=b25 'Nombre à décoder
symbol ADRESSE=b26 'Adresse mémoire de la note
'========================================================================
'Animation lumineuse des leds et des afficheurs permetttant d'attendre si
'le joueur souhaite paramétrer le jeu. Si une touche est actionnée durant
'ce délai, la sélection de niveau est demandée.
INTRO:
random ALEATOIRE
if COMPT2=0 then : pinsB=115 : endif
if COMPT2=1 then : pinsB=226 : endif
if COMPT2=2 then : pinsB=241 : endif
if COMPT2=3 then : pinsB=213 : endif
if COMPT2=4 then : pinsB=160 : endif
if COMPT2=5 then : pinsB=183 : endif
if COMPT2=6 then : COMPT1=0 : COMPT2=0 : goto DEBUT : endif
select case COMPT1
case 0 to 10
high BLEU : pinsD=4
low JAUNE : low VERT : low ROUGE : low BLANC
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR3
case 11 to 20
high JAUNE : pinsD=2
low BLEU : low VERT : low ROUGE : low BLANC
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR3
case 21 to 30
high VERT : pinsD=1
low BLEU : low JAUNE : low ROUGE : low BLANC
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR3
case 31 to 40
high ROUGE : pinsD=128
low BLEU : low JAUNE : low VERT : low BLANC
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR3
case 41 to 50
high BLANC : pinsD=32
low BLEU : low JAUNE : low VERT : low ROUGE
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR3
case 51 to 60
low BLANC : pinsD=16
low BLEU : low JAUNE : low VERT : low ROUGE
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR3
case 61
COMPT1=0
inc COMPT2
endselect
pause DUREE : inc COMPT1 : goto INTRO
'Procédure d'antirebonds: la touche doit être relâchée.
AR3:
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR3
'========================================================================
'1ère étape du paramétrage: choix du niveau: nombre de couleurs entre 2 et 5.
CHNIV:
gosub ARRET : pinsD=84 : readadc 0,NIVEAU
NIVEAU=NIVEAU/64 : NIVEAU=NIVEAU+2
if NIVEAU=2 then : pinsB=213 : endif
if NIVEAU=3 then : pinsB=241 : endif
if NIVEAU=4 then : pinsB=226 : endif
if NIVEAU=5 then : pinsB=115 : endif
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then
'Procédure d'antirebonds: la touche doit être relâchée.
AR1:
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR1
goto CHDUR
endif
goto CHNIV
'========================================================================
'2ème étape du paramétrage: choix de la durée des notes: entre 1 et 9.
CHDUR:
pinsD=244 : readadc 0,VITESSE : VITESSE=VITESSE/29 : inc VITESSE
if VITESSE=1 then : pinsB=160 : endif
if VITESSE=2 then : pinsB=213 : endif
if VITESSE=3 then : pinsB=241 : endif
if VITESSE=4 then : pinsB=226 : endif
if VITESSE=5 then : pinsB=115 : endif
if VITESSE=6 then : pinsB=119 : endif
if VITESSE=7 then : pinsB=161 : endif
if VITESSE=8 then : pinsB=247 : endif
if VITESSE=9 then : pinsB=243 : endif
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then
'Procédure d'antirebonds: la touche doit être relâchée.
AR2:
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR2
goto DEBUT
endif
goto CHDUR
'========================================================================
'Fin du paramétrage, s'il a été demandé.
DEBUT:
COMPT1=0 : COMPT2=0 : COMPT4=0 : gosub ARRET : pinsB=199 : pinsD=87
'========================================================================
'Boucle d'attente pour le départ du jeu. Durant cette phase un compteur
'tourne pour générer un nombre vraiment aléatoire au moment de l'appui sur
'une touche.
DEPART:
high BLEU : high JAUNE : high VERT : high ROUGE : high BLANC
inc COMPT4 : random ALEATOIRE
if COMPT4>99 then : COMPT4=0 : endif
if pinA.1=0 and pinA.2=0 and pinA.5=0 and pinA.6=0 and pinA.7=0 then DEPART
AR4:
if pinA.1=1 or pinA.2=1 or pinA.5=1 or pinA.6=1 or pinA.7=1 then AR4
gosub ARRET
'========================================================================
'Etape de mémorisation des 99 chiffres aléatoires (de 0 à 4 selon le niveau
'demandé).
MEMO:
CHOIX=0 : random ALEATOIRE
if NIVEAU=2 then : CHOIX=ALEATOIRE/32768 : endif
if NIVEAU=3 then : CHOIX=ALEATOIRE/21846 : endif
if NIVEAU=4 then : CHOIX=ALEATOIRE/16384 : endif
if NIVEAU=5 then : CHOIX=ALEATOIRE/13108 : endif
if COMPT2>139 then
COMPT1=COMPT2-30 : COMPT1=COMPT1-COMPT4
if ADRESSE>99 then DEPCYCLE
NOMBRE=ADRESSE : gosub AFFICHE : put ADRESSE,CHOIX : inc ADRESSE
endif
inc COMPT2
goto MEMO
'========================================================================
'Initialisation des variables pour le lancement du jeu.
DEPCYCLE:
COMPT1=0 : CYCLE=0 : ADRESSE=0
'========================================================================
'Départ du jeu: affichage des couleurs et génération des notes.
BOUCLE:
POSJEU=0 : NOMBRE=CYCLE+1 : gosub AFFICHE
for ADRESSE=0 to CYCLE : get ADRESSE,CHOIX : gosub JOUE : pause 300 : next
'========================================================================
'Attente et analyse de la réponse du joueur.
REPONSE:
NOMBRE=CYCLE+1 : gosub AFFICHE
if POSJEU>CYCLE then BIEN
get POSJEU,CHOIX
ATTENTE:
if pinA.1=1 then TJAUNE
if pinA.2=1 then TVERT
if pinA.5=1 then TBLEU
if pinA.6=1 then TBLANC
if pinA.7=1 then TROUGE
goto ATTENTE
TBLEU:
if CHOIX<>0 then FAUX
inc POSJEU : gosub JOUE : goto REPONSE
TJAUNE:
if CHOIX<>1 then FAUX
inc POSJEU : gosub JOUE : goto REPONSE
TVERT:
if CHOIX<>2 then FAUX
inc POSJEU : gosub JOUE : goto REPONSE
TROUGE:
if CHOIX<>3 then FAUX
inc POSJEU : gosub JOUE : goto REPONSE
TBLANC:
if CHOIX<>4 then FAUX
inc POSJEU : gosub JOUE : goto REPONSE
'========================================================================
'Mélodie de perte du jeu et retour à l'introduction, en cas de réponse fausse,
FAUX:
gosub ARRET
for COMPT3=100 to 20 step -5 : sound SON,(COMPT3,8) : next
sound SON,(15,100) : COMPT1=0 : COMPT2=0 : ADRESSE=0
goto INTRO
'========================================================================
'En cas de réponse juste, Bip sonore et suite du jeu avec ajout un pas supplémentaire
BIEN:
pause 250 : inc CYCLE : sound SON,(120,30) : pause 250
goto BOUCLE
'Traitement de la couleur et de la note dans le jeu en fonction du chiffre aléatoire
'relu en mémoire.
JOUE:
if VITESSE<15 then : VITESSE=VITESSE*25 : endif
if CHOIX=0 then : high BLEU : NOTE=CHOIX+1*20 : sound SON,(NOTE,VITESSE) : low BLEU : endif
if CHOIX=1 then : high JAUNE : NOTE=CHOIX+1*20 : sound SON,(NOTE,VITESSE) : low JAUNE : endif
if CHOIX=2 then : high VERT : NOTE=CHOIX+1*20 : sound SON,(NOTE,VITESSE) : low VERT : endif
if CHOIX=3 then : high ROUGE : NOTE=CHOIX+1*20 : sound SON,(NOTE,VITESSE) : low ROUGE : endif
if CHOIX=4 then : high BLANC : NOTE=CHOIX+1*20 : sound SON,(NOTE,VITESSE) : low BLANC : endif
return
'Affichage des nombres sur les afficheurs.
AFFICHE:
DIZAIN=NOMBRE/10 : CHIFFRE=DIZAIN : gosub DECODE : pinsD=CHIFFRE
UNITE=NOMBRE//10 : CHIFFRE=UNITE : gosub DECODE : pinsB=CHIFFRE
return
'Traitement de la valeur à attribuer au PortB ou au PortD en fonction du chiffre.
DECODE:
if CHIFFRE=0 then : CHIFFRE=183 : endif
if CHIFFRE=1 then : CHIFFRE=160 : endif
if CHIFFRE=2 then : CHIFFRE=213 : endif
if CHIFFRE=3 then : CHIFFRE=241 : endif
if CHIFFRE=4 then : CHIFFRE=226 : endif
if CHIFFRE=5 then : CHIFFRE=115 : endif
if CHIFFRE=6 then : CHIFFRE=119 : endif
if CHIFFRE=7 then : CHIFFRE=161 : endif
if CHIFFRE=8 then : CHIFFRE=247 : endif
if CHIFFRE=9 then : CHIFFRE=243 : endif
return