Hello everyone,
i just finished my trutle
Here it is...
Extras
PS: Oh yeah, i hate to fold paper now...
I hope you like it
i just finished my trutle
Here it is...
Extras
https://www.dropbox.com/s/fa87ys9bzvtz6u8/computercraft_turtle_controlboard.jpg
https://www.dropbox.com/s/4acxrndepzf0k04/JD600037.JPG
PCB(target3001 file): https://www.dropbox.com/s/vdhwmbc7y8wanri/Hauptplatine_masse.T3001
code:
https://www.dropbox.com/s/4acxrndepzf0k04/JD600037.JPG
PCB(target3001 file): https://www.dropbox.com/s/vdhwmbc7y8wanri/Hauptplatine_masse.T3001
code:
Code:
'Computer Craft Turtle
'Version: rl_2.0
'by Shizz0
$regfile = "m48pdef.dat"
$crystal = 16000000
$hwstack = 128
$swstack = 64
$framesize = 128
' vars
Dim Text As String * 1
Dim Letter_count As Byte
Dim Attack_counter As Byte , Servo_counter As Byte
Dim Dance_enable As Bit , Attack_enable As Bit
Dim Gps(3) As Byte
Dim Sensor As Word , Sensor_m2 As Bit
Dim ___rseed As Word , Random As Word
' I/O
Config Pind.0 = Output 'Servo
Config Pinc.5 = Input 'Sensor
Config Pind.1 = Input
Button1 Alias Pind.1
Portd.1 = 1
Config Pind.2 = Input
Anykey Alias Pind.2
Portd.2 = 1
Config Portb.3 = Output 'OC2A M1
Config Portd.3 = Output 'OC2B M1
Config Portb.1 = Output 'OC1A M2
Config Portb.2 = Output 'OC1B M2
' const
Const Slowtext = 1 'sec
Const Typingspeed = 200 'ms
Const Fasttext = 30 'ms
Const Block = 1945 'ms/block@255
Const Block_turn = 754 'ms/90° turn@255
' lcd
Config Lcdpin = Pin , Db7 = Portc.4 , Db6 = Portc.3 , Db5 = Portc.2 , _
Db4 = Portc.1 , Rs = Portb.5 , E = Portc.0
Config Lcd = 16 * 2
' adc
Config Adc = Single , Prescaler = Auto , Reference = Avcc
' servo
Config Servos = 1 , Servo1 = Portd.0 , Reload = 10
' timer
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , _
Compare B Pwm = Clear Down , Prescale = 64
Enable Timer1
Config Timer2 = Pwm , Pwm = On , Compare A Pwm = Clear Down , _
Compare B Pwm = Clear Down , Prescale = 64
Enable Timer2
' ints
Config Int0 = Falling
Enable Int0
On Int0 On_int0
Enable Interrupts
' startup
Declare Sub Motor(byval Direction As Byte , Byval Speed As Byte)
Call Motor(5 , 0)
Wait 1
Call Motor(5 , 0)
Initlcd
Gosub Startingscreen
Wait 5
Call Motor(7 , 75)
Waitms 4800
Call Motor(7 , 0)
' main
Do
Debounce Button1 , 0 , Dance , Sub
If Attack_enable = 1 Then
Gosub Attack
End If
Loop
End
' subs
' ###########################################################################
'Test1:
'Wait 3
'Call Motor(2 , 255)
'Return
Fucking_random_dance:
Set Dance_enable
Gps(1) = 3
Gps(2) = 3
Gps(3) = 0
While Dance_enable = 1
___rseed = Tcnt0
Random = Rnd(5)
Select Case Random
Case 0:
Select Case Gps(3)
Case 0:
If Gps(2) > 1 Then
Decr Gps(2)
Call Motor(0 , 255)
End If
Case 1:
If Gps(1) < 5 Then
Incr Gps(1)
Call Motor(0 , 255)
End If
Case 2:
If Gps(2) < 5 Then
Incr Gps(2)
Call Motor(0 , 255)
End If
Case 3:
If Gps(1) > 1 Then
Decr Gps(1)
Call Motor(0 , 255)
End If
End Select
Case 1:
Select Case Gps(3)
Case 0:
If Gps(2) < 5 Then
Incr Gps(2)
Call Motor(1 , 255)
End If
Case 1:
If Gps(1) > 1 Then
Decr Gps(1)
Call Motor(1 , 255)
End If
Case 2:
If Gps(2) > 1 Then
Decr Gps(2)
Call Motor(1 , 255)
End If
Case 3:
If Gps(1) < 5 Then
Incr Gps(1)
Call Motor(1 , 255)
End If
End Select
Case 2:
If Gps(3) = 3 Then
Gps(3) = 255
End If
Incr Gps(3)
Call Motor(2 , 255)
Case 3:
If Gps(3) = 0 Then
Gps(3) = 4
End If
Decr Gps(3)
Call Motor(3 , 255)
Case 4:
Call Motor(5 , 0)
End Select
Waitms 200
Wend
Return
' ###########################################################################
Sub Motor(byval Direction As Byte , Byval Speed As Byte)
Select Case Direction
Case 0: '1 block fwd
Pwm1a = Speed
Pwm2a = Speed
Waitms Block
Pwm1a = 0
Pwm2a = 0
Case 1: '1 block bwd
Pwm1b = Speed
Pwm2b = Speed
Waitms Block
Pwm1b = 0
Pwm2b = 0
Case 2: '90° right
Pwm1b = Speed
Pwm2a = Speed
Waitms Block_turn
Pwm1b = 0
Pwm2a = 0
Case 3: '90° left
Pwm1a = Speed
Pwm2b = Speed
Waitms Block_turn
Pwm1a = 0
Pwm2b = 0
Case 4: 'fwd
Pwm1a = Speed
Pwm2a = Speed
Case 5: 'Servo
For Servo_counter = 70 To 100
Servo(1) = Servo_counter
Waitms 3
Next
Waitms 100
For Servo_counter = 100 To 70 Step -1
Servo(1) = Servo_counter
Waitms 3
Next
Waitms 100
Case 6: 'turn left
Pwm1a = Speed
Pwm2b = Speed
Case 7: 'turn right
Pwm1b = Speed
Pwm2a = Speed
End Select
End Sub
' ###########################################################################
On_int0:
'NEVER run ADC, SERVO or PWM routines while the "return-adress" of an interrupt
'is on the HWstack !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reset Dance_enable
Reset Attack_enable
Reset Sensor_m2
Gosub Startingscreen
Waitms 500
If Anykey = 0 Then
Set Attack_enable
End If
Return
' ###########################################################################
Attack:
Waitms 500
Start Adc
For Letter_count = 0 To 5
Text = Lookupstr(letter_count , Attack_text)
Lcd Text
Waitms Typingspeed
Next
Wait 2
Call Motor(6 , 70)
Sensor_m2 = 1
While Attack_enable = 1
Sensor = Getadc(5)
If Sensor >= 150 And Sensor_m2 = 1 Then
Sensor_m2 = 0
Call Motor(6 , 0)
Wait 1
Call Motor(4 , 70)
Elseif Sensor >= 550 Then
Attack_enable = 0
Stop Adc
Call Motor(4 , 0)
Waitms 500
Call Motor(5 , 0)
Locate 2 , 9 : Lcd "-done"
Wait 5
Gosub Startingscreen
End If
Waitms 5
Wend
Return
' ###########################################################################
Startingscreen:
Cursor Off Noblink
Cls
Lcd "TurtleOS 9000.1"
Locate 2 , 1
Lcd "> "
Cursor On Blink
Return
' ###########################################################################
Dance:
Waitms 500
If Button1 = 0 Then
Wait 5
Cls
For Attack_counter = 1 To 10
If Attack_counter <= 6 Then
If Attack_counter = 4 Then
Locate 2 , 1
End If
Lcd "KILL "
End If
Call Motor(5 , 0)
Next
Wait 2
Gosub Startingscreen
Else
Disable Int0
For Letter_count = 0 To 27
If Letter_count = 5 Then
Wait 2
Cls
Cursor Off Noblink
Locate 1 , 1
Elseif Letter_count = 21 Then
Locate 2 , 1
End If
Text = Lookupstr(letter_count , Dance_text)
Lcd Text
If Letter_count <= 4 Then
Waitms Typingspeed
Elseif Letter_count > 4 And Letter_count < 24 Then
Waitms Fasttext
Else
Wait Slowtext
End If
Next
Wait 2
Cls
Locate 1 , 1
Lcd "Press any key to"
Locate 2 , 1
Lcd "stop the groove"
Wait 1
Enable Int0
Gosub Fucking_random_dance
End If
Return
' ###########################################################################
'----------------
'----- data -----
'----------------
Dance_text:
Data "d" , "a" , "n" , "c" , "e"
Data "P" , "r" , "e" , "p" , "a" , "r" , "i" , "n" , "g" , " "
Data "t" , "o" , " "
Data "g" , "e" , "t"
Data "d" , "o" , "w" , "n" , "." , "." , "."
Attack_text:
Data "a" , "t" , "t" , "a" , "c" , "k"
PS: Oh yeah, i hate to fold paper now...
I hope you like it