# Deklarationen var s = 0 # Schrittzähler var schrittzahl = 0 # Anzahl der Schritte im Programm var max = 100 # Maximale Anzahl Schritte im Programm var schritt[100] var zustand = 0 call leds.top(0,0,0) call leds.circle(0,0,0,0,0,0,0,0) sub vorwaerts motor.left.target = MOTOR motor.right.target = MOTOR sub zurueck motor.left.target = -MOTOR motor.right.target = -MOTOR sub rechts motor.left.target = MOTORDREHEN motor.right.target = -MOTORDREHEN sub links motor.left.target = -MOTORDREHEN motor.right.target = MOTORDREHEN sub stopp motor.left.target = 0 motor.right.target = 0 sub zustand0 zustand = 0 call sound.system(3) call leds.top(0,0,0) call leds.circle(0,0,0,0,0,0,0,0) callsub stopp sub zustand1 zustand = 1 call sound.system(3) call leds.top(0,32,0) schrittzahl = 0 s = 0 sub zustand2 zustand = 2 call sound.system(3) call leds.top(32,32,0) schrittzahl = s # Schrittzahl merken für Zeige-Zustand s = 0 # Zähler für nächsten Zustand zurücksetzen timer.period[0] = MILLIS # Nach MILLIS ms kommt der erste timer0 event sub zustand3 zustand = 3 call sound.system(3) call leds.top(0,0,32) s = 0 # Zähler für nächsten Zustand zurücksetzen timer.period[0] = MILLISMOTOR onevent button.center if button.center == 1 then if zustand == 0 then # Initialzustand callsub zustand1 elseif zustand == 1 then # Lernzustand callsub zustand2 elseif zustand == 2 then callsub zustand3 elseif zustand == 3 then callsub zustand0 end end onevent button.right if button.right == 1 then # Button ist gedrückt und nicht losgelassen if zustand == 1 then # Nur im Zustand1 das Folgende auführen schritt[s] = RECHTS # Schritt speichern s++ # Schrittzähler eins vor call sound.system(5) # Rückmeldung end end onevent button.left if button.left == 1 then if zustand == 1 then schritt[s] = LINKS s++ call sound.system(5) end end onevent button.forward if button.forward == 1 then if zustand == 1 then schritt[s] = VOR s++ call sound.system(5) end end onevent button.backward if button.backward == 1 then if zustand == 1 then schritt[s] = ZURUECK s++ call sound.system(5) end end onevent timer0 if zustand == 2 then # Nur im Zustand 2 das Folgende ausführen if s == schrittzahl then timer.period[0] = 0 call leds.circle(0,0,0,0,0,0,0,0) call sound.system(3) callsub zustand3 else if schritt[s] == RECHTS then call leds.circle(0,0,32,0,0,0,0,0) elseif schritt[s] == LINKS then call leds.circle(0,0,0,0,0,0,32,0) elseif schritt[s] == VOR then call leds.circle(32,0,0,0,0,0,0,0) elseif schritt[s] == ZURUECK then call leds.circle(0,0,0,0,32,0,0,0) end call sound.system(5) s++ end elseif zustand == 3 then if s == schrittzahl then timer.period[0] = 0 call leds.circle(0,0,0,0,0,0,0,0) call sound.system(3) callsub stopp callsub zustand0 else if schritt[s] == RECHTS then call leds.circle(0,0,32,0,0,0,0,0) callsub rechts elseif schritt[s] == LINKS then call leds.circle(0,0,0,0,0,0,32,0) callsub links elseif schritt[s] == VOR then call leds.circle(32,0,0,0,0,0,0,0) callsub vorwaerts elseif schritt[s] == ZURUECK then call leds.circle(0,0,0,0,32,0,0,0) callsub zurueck end call sound.system(5) s++ end end