avus17
17.12.2013, 20:05
Hallo zusammen ich versuche nun schon etwas länger ein "Spiel" in Bascom zu programmieren.
Dazu soll zufällig erst eine Lampe leuchten, wenn nun der entsprechende Taster gedrückt wird soll
die Erste LED noch mal leuchten und kurz darauf eine zweite zufällige usw. also eine Art Merkspiel.
Mein Problem ist nun, dass ich es irgendwie nicht hinbekomme den eingegebenen Code einzulesen.
Kann mir da mal jemand bei helfen? Hab gerade irgendwie ein Brett vorm Kopf :)
$regfile = "m8def.dat "
$crystal = 1000000
Config Portd.0 = Output
Config Portd.1 = Output
Config Portd.2 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Config Portb.0 = Output
Config Pinc.5 = Input
Config Pinc.4 = Input
Config Pinc.3 = Input
Config Pinc.2 = Input
Config Pinc.1 = Input
Config Pinc.0 = Input
Config Pinb.5 = Input
Config Pinb.4 = Input
'Pullups Setzen
Portc.5 = 1
Portc.4 = 1
Portc.3 = 1
Portc.2 = 1
Portc.1 = 1
Portc.0 = 1
Portb.5 = 1
Portb.4 = 1
Taster8 Alias Pinc.5
Taster7 Alias Pinc.4
Taster6 Alias Pinc.3
Taster4 Alias Pinc.2
Taster5 Alias Pinc.1
Taster1 Alias Pinc.0
Taster2 Alias Pinb.5
Taster3 Alias Pinb.4
Ledblau Alias Portb.0
Led6 Alias Portd.0
Led4 Alias Portd.1
Led1 Alias Portd.2
Led7 Alias Portd.3
Led2 Alias Portd.4
Led8 Alias Portd.5
Led5 Alias Portd.6
Led3 Alias Portd.7
'Erzeugter Code
Dim Code(8) As Byte
' Aktuelle Stelle
Dim Aktstelle As Byte
' Verzögerung in ms
Dim Verz As Byte
Dim Count As Byte
Dim Tasternummer As Byte
Aktstelle = 1
Verz = 250
Do
If Taster1 = 0 Then
Gosub Codeerstellen
Gosub Lauflicht
Gosub Lauflicht
Gosub Codelesen
End If
Loop
'************************************************* ******************************
Codeerstellen:
Count = 0
While Count <= 8
Code(count) = Rnd(7)
Code(count) = Code(count) + 1
Count = Count + 1
Wend
Return
'************************************************* ******************************
Lauflicht:
Led1 = 1
Waitms 100
Led1 = 0
Waitms 100
Led2 = 1
Waitms 100
Led2 = 0
Waitms 100
Led3 = 1
Waitms 100
Led3 = 0
Waitms 100
Led5 = 1
Waitms 100
Led5 = 0
Waitms 100
Led8 = 1
Waitms 100
Led8 = 0
Waitms 100
Led7 = 1
Waitms 100
Led7 = 0
Waitms 100
Led6 = 1
Waitms 100
Led6 = 0
Waitms 100
Led4 = 1
Waitms 100
Led4 = 0
Waitms 100
Return
'************************************************* ******************************
Codeanzeigen:
Count = 0
While Count < Aktstelle
If Code(count) = 1 Then
Led1 = 1
Waitms Verz
Led1 = 0
Waitms Verz
End If
If Code(count) = 2 Then
Led2 = 1
Waitms Verz
Led2 = 0
Waitms Verz
End If
If Code(count) = 3 Then
Led3 = 1
Waitms Verz
Led3 = 0
Waitms Verz
End If
If Code(count) = 4 Then
Led4 = 1
Waitms Verz
Led4 = 0
Waitms Verz
End If
If Code(count) = 5 Then
Led5 = 1
Waitms Verz
Led5 = 0
Waitms Verz
End If
If Code(count) = 6 Then
Led6 = 1
Waitms Verz
Led6 = 0
Waitms Verz
End If
If Code(count) = 7 Then
Led7 = 1
Waitms Verz
Led7 = 0
Waitms Verz
End If
If Code(count) = 8 Then
Led8 = 1
Waitms Verz
Led8 = 0
Waitms Verz
End If
Count = Count + 1
Wend
Return
'************************************************* ******************************
Tasteridentifizieren:
Return
If Taster1 = 0 Then
Tasternummer = 1
End If
If Taster2 = 0 Then
Tasternummer = 2
End If
If Taster3 = 0 Then
Tasternummer = 3
End If
If Taster4 = 0 Then
Tasternummer = 4
End If
If Taster5 = 0 Then
Tasternummer = 5
End If
If Taster6 = 0 Then
Tasternummer = 6
End If
If Taster7 = 0 Then
Tasternummer = 7
End If
If Taster8 = 0 Then
Tasternummer = 8
Else
Tasternummer = 0
End If
'************************************************* ******************************
Tasteeinlesen:
Led1 = 1
Waitms 800
Gosub Tasteridentifizieren
Waitms 300
Led1 = 0
Return
'************************************************* ******************************
Codelesen:
Waitms 300
Gosub Codeanzeigen
Gosub Tasteeinlesen
If Tasternummer = Code(1) Then
Aktstelle = 2
Waitms 300
Gosub Codeanzeigen
Gosub Tasteeinlesen
If Tasternummer = Code(2) Then
Aktstelle = 3
Waitms 300
Gosub Codeanzeigen
Gosub Tasteeinlesen
End If
End If
Return
EDIT:
Hat jemand eine Idee wie ich jetzt mehrere Taster nacheinander auslesen kann???
Dazu soll zufällig erst eine Lampe leuchten, wenn nun der entsprechende Taster gedrückt wird soll
die Erste LED noch mal leuchten und kurz darauf eine zweite zufällige usw. also eine Art Merkspiel.
Mein Problem ist nun, dass ich es irgendwie nicht hinbekomme den eingegebenen Code einzulesen.
Kann mir da mal jemand bei helfen? Hab gerade irgendwie ein Brett vorm Kopf :)
$regfile = "m8def.dat "
$crystal = 1000000
Config Portd.0 = Output
Config Portd.1 = Output
Config Portd.2 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Config Portb.0 = Output
Config Pinc.5 = Input
Config Pinc.4 = Input
Config Pinc.3 = Input
Config Pinc.2 = Input
Config Pinc.1 = Input
Config Pinc.0 = Input
Config Pinb.5 = Input
Config Pinb.4 = Input
'Pullups Setzen
Portc.5 = 1
Portc.4 = 1
Portc.3 = 1
Portc.2 = 1
Portc.1 = 1
Portc.0 = 1
Portb.5 = 1
Portb.4 = 1
Taster8 Alias Pinc.5
Taster7 Alias Pinc.4
Taster6 Alias Pinc.3
Taster4 Alias Pinc.2
Taster5 Alias Pinc.1
Taster1 Alias Pinc.0
Taster2 Alias Pinb.5
Taster3 Alias Pinb.4
Ledblau Alias Portb.0
Led6 Alias Portd.0
Led4 Alias Portd.1
Led1 Alias Portd.2
Led7 Alias Portd.3
Led2 Alias Portd.4
Led8 Alias Portd.5
Led5 Alias Portd.6
Led3 Alias Portd.7
'Erzeugter Code
Dim Code(8) As Byte
' Aktuelle Stelle
Dim Aktstelle As Byte
' Verzögerung in ms
Dim Verz As Byte
Dim Count As Byte
Dim Tasternummer As Byte
Aktstelle = 1
Verz = 250
Do
If Taster1 = 0 Then
Gosub Codeerstellen
Gosub Lauflicht
Gosub Lauflicht
Gosub Codelesen
End If
Loop
'************************************************* ******************************
Codeerstellen:
Count = 0
While Count <= 8
Code(count) = Rnd(7)
Code(count) = Code(count) + 1
Count = Count + 1
Wend
Return
'************************************************* ******************************
Lauflicht:
Led1 = 1
Waitms 100
Led1 = 0
Waitms 100
Led2 = 1
Waitms 100
Led2 = 0
Waitms 100
Led3 = 1
Waitms 100
Led3 = 0
Waitms 100
Led5 = 1
Waitms 100
Led5 = 0
Waitms 100
Led8 = 1
Waitms 100
Led8 = 0
Waitms 100
Led7 = 1
Waitms 100
Led7 = 0
Waitms 100
Led6 = 1
Waitms 100
Led6 = 0
Waitms 100
Led4 = 1
Waitms 100
Led4 = 0
Waitms 100
Return
'************************************************* ******************************
Codeanzeigen:
Count = 0
While Count < Aktstelle
If Code(count) = 1 Then
Led1 = 1
Waitms Verz
Led1 = 0
Waitms Verz
End If
If Code(count) = 2 Then
Led2 = 1
Waitms Verz
Led2 = 0
Waitms Verz
End If
If Code(count) = 3 Then
Led3 = 1
Waitms Verz
Led3 = 0
Waitms Verz
End If
If Code(count) = 4 Then
Led4 = 1
Waitms Verz
Led4 = 0
Waitms Verz
End If
If Code(count) = 5 Then
Led5 = 1
Waitms Verz
Led5 = 0
Waitms Verz
End If
If Code(count) = 6 Then
Led6 = 1
Waitms Verz
Led6 = 0
Waitms Verz
End If
If Code(count) = 7 Then
Led7 = 1
Waitms Verz
Led7 = 0
Waitms Verz
End If
If Code(count) = 8 Then
Led8 = 1
Waitms Verz
Led8 = 0
Waitms Verz
End If
Count = Count + 1
Wend
Return
'************************************************* ******************************
Tasteridentifizieren:
Return
If Taster1 = 0 Then
Tasternummer = 1
End If
If Taster2 = 0 Then
Tasternummer = 2
End If
If Taster3 = 0 Then
Tasternummer = 3
End If
If Taster4 = 0 Then
Tasternummer = 4
End If
If Taster5 = 0 Then
Tasternummer = 5
End If
If Taster6 = 0 Then
Tasternummer = 6
End If
If Taster7 = 0 Then
Tasternummer = 7
End If
If Taster8 = 0 Then
Tasternummer = 8
Else
Tasternummer = 0
End If
'************************************************* ******************************
Tasteeinlesen:
Led1 = 1
Waitms 800
Gosub Tasteridentifizieren
Waitms 300
Led1 = 0
Return
'************************************************* ******************************
Codelesen:
Waitms 300
Gosub Codeanzeigen
Gosub Tasteeinlesen
If Tasternummer = Code(1) Then
Aktstelle = 2
Waitms 300
Gosub Codeanzeigen
Gosub Tasteeinlesen
If Tasternummer = Code(2) Then
Aktstelle = 3
Waitms 300
Gosub Codeanzeigen
Gosub Tasteeinlesen
End If
End If
Return
EDIT:
Hat jemand eine Idee wie ich jetzt mehrere Taster nacheinander auslesen kann???