Lightcube/erste Animation

Aus C3MAWiki
Version vom 10. Januar 2008, 13:21 Uhr von Scytale (Diskussion | Beiträge) (hat Lightcube:erste Animation nach Lightcube/erste Animation verschoben: Der Trenner für Namespaces ist ":", der für Unterseiten ist "/"; das hier verwirrt nur die Software und mich. ;))
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Dieses Projekt ist erfolgreich abgeschlossen und wird hier dokumentiert. Falls du weitere Fragen dazu hast, wende dich an TheMaverick.


Hier sind mal die ersten Testanimationen.

Da die Datenübertragung vom PC an den Cube noch nicht gunktioniert gibts hier ausschließlich Statische animationen

$regfile = "m32def.dat" $crystal = 16000000


Config Porta = Output Config Portb = Output Config Portc = Output

Declare Sub Moving_wall_front_back() Declare Sub Moving_wall_top_bottom() Declare Sub Randum_levels() Declare Sub Randum_led_to_all() Declare Sub Randum_led() Declare Sub Randum_leds() Declare Sub Moving_cube() Declare Sub Snake() Declare Sub Light_one_led(byval Led_x As Byte , Byval Led_y As Byte , Byval Led_z As Byte) Declare Sub Dark_one_led(byval Led_x As Byte , Byval Led_y As Byte , Byval Led_z As Byte) Declare Sub Dark()

Dim X As Byte Dim Y As Byte Dim Z As Byte Dim P As Byte

Dim Istx As Byte Dim Isty As Byte Dim Istz As Byte Dim Istx1 As Byte Dim Isty1 As Byte Dim Istz1 As Byte Dim Istx2 As Byte Dim Isty2 As Byte Dim Istz2 As Byte Dim Istx3 As Byte Dim Isty3 As Byte Dim Istz3 As Byte

Dim Move As Byte Dim Movex As Byte Dim Movey As Byte Dim Movez As Byte

'hauptschleife aufrufen

'Call Moving_wall_front_back() 'Call Moving_wall_top_bottom() 'Call Randum_levels() 'Call Randum_led_to_all() 'Call Randum_led() 'Call Randum_leds() Call Moving_cube() 'Call Snake()


Sub Randum_leds() 'eine zufällige led wird aktiviert Do

  Istx1 = Rnd(9)
  If Istx1 > 0 Then
  Istx1 = Istx1 - 1
  End If
  Isty1 = Rnd(9)
  If Isty1 > 0 Then
  Isty1 = Isty1 - 1
  End If
  Istz1 = Rnd(9)
  If Istz1 > 0 Then
  Istz1 = Istz1 - 1
  End If
  Istx2 = Rnd(9)
  If Istx2 > 0 Then
  Istx2 = Istx2 - 1
  End If
  Isty2 = Rnd(9)
  If Isty2 > 0 Then
  Isty2 = Isty2 - 1
  End If
  Istz2 = Rnd(9)
  If Istz2 > 0 Then
  Istz2 = Istz2 - 1
  End If
  Istx3 = Rnd(9)
  If Istx3 > 0 Then
  Istx3 = Istx3 - 1
  End If
  Isty3 = Rnd(9)
  If Isty3 > 0 Then
  Isty3 = Isty3 - 1
  End If
  Istz3 = Rnd(9)
  If Istz3 > 0 Then
  Istz3 = Istz3 - 1
  End If
  For P = 1 To 30 Step 1
     Call Dark()
     Call Light_one_led(istx1 , Isty1 , Istz1)
     Waitms 2
     Call Dark()
     Call Light_one_led(istx2 , Isty2 , Istz2)
     Waitms 2
     Call Dark()
     Call Light_one_led(istx3 , Isty3 , Istz3)
     Waitms 2
  Next P

Loop 'Until P = 25 End Sub Randum_leds()




 Sub Snake()

'es bildet sich eine schlange aus leds die sich dirch den würfel schlängelt X = 0 Y = 0 Z = 0

Dim Snake1x As Byte Dim Snake1y As Byte Dim Snake1z As Byte Dim Snake2x As Byte Dim Snake2y As Byte Dim Snake2z As Byte Dim Snake3x As Byte Dim Snake3y As Byte Dim Snake3z As Byte Dim Snake4x As Byte Dim Snake4y As Byte Dim Snake4z As Byte

Snake1x = 3 Snake1y = 0 Snake1z = 0

Snake2x = 2 Snake2y = 0 Snake2z = 0

Snake3x = 1 Snake3y = 0 Snake3z = 0

Snake4x = 0 Snake4y = 0 Snake4z = 0

Do


  For P = 1 To 100 Step 1
     Call Light_one_led(snake1x , Snake1y , Snake1z)
     Waitus 1000
     Call Dark_one_led(snake1x , Snake1y , Snake1z)
     Call Light_one_led(snake2x , Snake2y , Snake2z)
     Waitus 1000
     Call Dark_one_led(snake2x , Snake2y , Snake2z)
     Call Light_one_led(snake3x , Snake3y , Snake3z)
     Waitus 1000
     Call Dark_one_led(snake3x , Snake3y , Snake3z)
     Call Light_one_led(snake4x , Snake4y , Snake4z)
     Waitus 1000
     Call Dark_one_led(snake4x , Snake4y , Snake4z)
  Next P
  Snake4x = Snake3x
  Snake4y = Snake3y
  Snake4z = Snake3z
  Snake3x = Snake2x
  Snake3y = Snake2y
  Snake3z = Snake2z
  Snake2x = Snake1x
  Snake2y = Snake1y
  Snake2z = Snake1z
  Move = Rnd(5)
  If Move = 0 Then
     If Snake1x <= 6 Then
        Snake1x = Snake1x + 1
     Else
        Snake1x = Snake1x - 1
     End If
  Elseif Move = 1 Then
     If Snake1x >= 1 Then
        Snake1x = Snake1x - 1
     Else
        Snake1x = Snake1x + 1
     End If


  Elseif Move = 2 Then
     If Snake1y <= 6 Then
        Snake1y = Snake1y + 1
     Else
        Snake1y = Snake1y - 1
     End If
  Elseif Move = 3 Then
     If Snake1y >= 1 Then
        Snake1y = Snake1y - 1
     Else
        Snake1y = Snake1y + 1
     End If


  Elseif Move = 4 Then
     If Snake1y <= 6 Then
        Snake1z = Snake1z + 1
     Else
        Snake1z = Snake1z - 1
     End If
  Elseif Move = 5 Then
     If Snake1y >= 1 Then
        Snake1z = Snake1z - 1
     Else
        Snake1z = Snake1z + 1
     End If
  End If

Loop

End Sub Snake()



Sub Moving_cube() 'ein würfel 3x3x3 leds bewegt sich frei nach zufall im LED cube X = 1 Y = 1 Z = 1


Do

  Call Dark()
  Porta.x = 1
     Istx = X - 1
  Porta.istx = 1
     Istx = X + 1
  Porta.istx = 1
  Portb.y = 1
     Isty = Y - 1
  Portb.isty = 1
     Isty = Y + 1
  Portb.isty = 1
  Portc.z = 1
     Istz = Z - 1
  Portc.istz = 1
     Istz = Z + 1
  Portc.istz = 1


  P = Rnd(3)
  Move = Rnd(10)
  Movex = Rnd(11)
  Movey = Rnd(11)
  Movez = Rnd(11)


  If P = 0 Then
     If Movex >= 5 Then
        If X <= 5 Then
           X = X + 1
        Else
           X = X - 1
        End If
     Else
        If X >= 2 Then
           X = X - 1
        Else
           X = X + 1
        End If
     End If
  Elseif P = 1 Then
     If Movey >= 5 Then
        If Y <= 5 Then
           Y = Y + 1
        Elseif Y >= 5 Then
           Y = Y - 1
        End If
     Else
        If Y >= 2 Then
           Y = Y - 1
        Elseif Y <= 2 Then
           Y = Y + 1
        End If
     End If
  Elseif P = 2 Then


     If Movez >= 5 Then
        If Z <= 5 Then
           Z = Z + 1
        Else
           Z = Z - 1
        End If
     Else
        If Z >= 2 Then
           Z = Z - 1
        Else
           Z = Z + 1
        End If
     End If
  End If
  Waitms 300

Loop

End Sub Moving_cube()



Sub Randum_led() 'eine zufällige led wird aktiviert P = 0 Do

  Call Dark()
  Istx = Rnd(9)
  Isty = Rnd(9)
  Istz = Rnd(9)
  Call Light_one_led(istx , Isty , Istz)


  Waitms 60
  P = P + 1

Loop 'Until P = 25 End Sub Randum_led()



Sub Randum_led_to_all() 'eine zufällige led wird aktiviert Do

  Istx = Rnd(9)
  Isty = Rnd(9)
  Istz = Rnd(9)
  Call Light_one_led(istx , Isty , Istz)
  Waitms 150

Loop End Sub Randum_led_to_all()



Sub Randum_levels() 'einzelne ebenenwerden frei nach belieben an und aus geschaltet P = 0 Do

  Istx = Rnd(9)
  Isty = Rnd(9)
  Istz = Rnd(9)
  Call Dark_one_led(istx , Isty , Istz)
  Istx = Rnd(9)
  Isty = Rnd(9)
  Istz = Rnd(9)
  Call Light_one_led(istx , Isty , Istz)
  Waitms 150
  P = P + 1

Loop 'Until P = 25 End Sub Randum_levels()


Sub Moving_wall_top_bottom() 'senkrechte wand wandert von oben nach unten und wieder zurück P = 0 Do

 For Z = 1 To 8 Step 1
        For Y = 1 To 8 Step 2
           For X = 1 To 8 Step 8
              Call Dark()
              Istx = X - 1
              Isty = Y - 1
              Istz = Z - 1
              Porta = 255
              Portc.isty = 1
              Isty = Isty + 1
              Portc.isty = 1
              Portb.istz = 1
              Waitms 10
           Next X
        Next Y
  Next Z
  For Z = 2 To 7 Step 1
        For Y = 1 To 8 Step 2
           For X = 1 To 8 Step 8
              Call Dark()
              Istx = X - 1
              Isty = Y - 1
              Istz = 8 - Z
              Porta = 255
              Portc.isty = 1
              Isty = Isty + 1
              Portc.isty = 1
              Portb.istz = 1
              Waitms 10
           Next X
        Next Y
  Next Z
  P = P + 1

Loop Until P = 10 End Sub Moving_wall_top_bottom()



Sub Moving_wall_front_back() 'senkrechte wand wandert von vorn nach hinten und wieder zurück P = 0 Do

 For Z = 1 To 8 Step 1
        For Y = 1 To 8 Step 2
           For X = 1 To 8 Step 8
              Call Dark()
              Istx = X - 1
              Isty = Y - 1
              Istz = Z - 1
              Porta = 255
              Portb.isty = 1
              Isty = Isty + 1
              Portb.isty = 1
              Portc.istz = 1
              Waitms 10
           Next X
        Next Y
  Next Z
  For Z = 2 To 7 Step 1
        For Y = 1 To 8 Step 2
           For X = 1 To 8 Step 8
              Call Dark()
              Istx = X - 1
              Isty = Y - 1
              Istz = 8 - Z
              Porta = 255
              Portb.isty = 1
              Isty = Isty + 1
              Portb.isty = 1
              Portc.istz = 1
              Waitms 10
           Next X
        Next Y
  Next Z
  P = P + 1

Loop Until P = 10 End Sub Moving_wall_front_back()


Sub Light_one_led(byval Led_x As Byte , Byval Led_y As Byte , Byval Led_z As Byte)

  Porta.led_x = 1
  Portb.led_y = 1
  Portc.led_z = 1

End Sub


Sub Dark_one_led(byval Led_x As Byte , Byval Led_y As Byte , Byval Led_z As Byte)

  Porta.led_x = 0
  Portb.led_y = 0
  Portc.led_z = 0

End Sub


Sub Dark()

  Porta = 0
  Portb = 0
  Portc = 0

End Sub


End
--TM 22:50, 2. Dez. 2006 (CET)