◀ Previous Next ▶ Up ▲


witpoko.com


ผมอยากทราบคำสั่งของ BASIC Stamp SX2 คำสั่งต่อไปนี้ครับขอบคุณครับ

'{$STAMP BS2sx}
'This program allows you to alter some of the operating parameters of the robot via
'a simple operator interface. The operator interface consists of 2 push buttons and
'an LCD display.
'
' Basic Stamp I/O Pin

OUTPUT 0 'Motor B(+)
OUTPUT 1 'Motor B(-)
OUTPUT 2 'Motor A(+)
OUTPUT 3 'Motor A(-)
OUTPUT 4 'IRPD Left IR LED
OUTPUT 5 'IRPD Right IR LED
INPUT 6 'IRPD Sensor output
INPUT 7 'Serial Display LCD (** Remote Control Channel 0 (RC Up)
INPUT 8 'Right Photoresistors LDR (** Remote Control Channel 1 (RC Down)
INPUT 9 'Center Photoresistors LDR (** Remote Control Channel 2 (RC Left)
INPUT 10 'Left Photoresistors LDR (** Remote Control Channel 3 (RC Right)
OUTPUT 11 'Piezo Speaker
OUTPUT 12 'Right LED
OUTPUT 13 'Left LED
INPUT 14 'Pushbutton A (** Right Bumper Sensor **)
INPUT 15 'Pushbutton B (** Left Bumper Sensor **)

'--------------------------------------------------------------------------

sony_IR CON 6 'Infrared Detector
spk CON 11
NegEdge CON 0 'For 0-1-0 config,IR remote PULSIN
Baud9600 CON $4054
notes VAR Nib 'Index for notes in lookup table.
frequency VAR Word 'Stores lookup table result.
button1 VAR IN15 'play button
button2 VAR IN14 'select next song button
templ VAR Word
tempr VAR Word
action VAR Nib
x VAR Word


'output 7 'Serial Display LCD

START:

PAUSE 100
' serout 7,Baud9600,5,["<<BATTER ROVER>> "]
' serout 7,baud9600,5,["A=Select B=Next "]
PAUSE 200

IF button1 = 0 THEN menu1 'Read pushbuttons

MENU1:
IF button1=0 THEN menu1
IF button2=0 THEN menu1
' serout 7,baud9600,5,["Infrared Sensor "]
' serout 7,baud9600,5,["A=Select B=Next "]
DEBUG HOME," Program INFRARED SENSOR "
menu1a:
IF button1=0 THEN IRPD1
IF button2=0 THEN menu2
GOTO menu1a

MENU2:
IF button1=0 THEN menu2
IF button2=0 THEN menu2
' serout 7,baud9600,5,["Bumper Sensor "]
' serout 7,baud9600,5,["A=Select B=Next "]
DEBUG HOME," Program BUMPER SWITCH "
menu2a:
IF button1=0 THEN BUMPER1
IF button2=0 THEN menu3
GOTO menu2a

MENU3:
IF button1=0 THEN menu3
IF button2=0 THEN menu3
' serout 7,baud9600,5,["Sound Speaker "]
' serout 7,baud9600,5,["A=Select B=Next "]
DEBUG HOME," Program SOUND SPEAKER "
menu3a:
IF button1=0 THEN SOUND1
IF button2=0 THEN menu4
GOTO menu3a

MENU4:
IF button1=0 THEN menu4
IF button2=0 THEN menu4
' serout 7,baud9600,5,["REMOTE CONTROL "]
' serout 7,baud9600,5,["A=Select B=Next "]
DEBUG HOME," Program REMOTE CONTROL "
menu4a:
IF button1=0 THEN RC1
IF button2=0 THEN menu5
GOTO menu4a

MENU5:
IF button1=0 THEN menu5
IF button2=0 THEN menu5
' serout 7,baud9600,5,["Tracker Lines "]
' serout 7,baud9600,5,["A=Select B=Next "]
DEBUG HOME," Program TRACKER LINE "
menu5a:
IF button1=0 THEN LTRACK1
IF button2=0 THEN menu1
GOTO menu5a


'---------- Programs Bumper switch --------------------------------------

BUMPER1:

INPUT 14 'Left Bumper Sensor (Switch)
INPUT 15 'Right Bumper Sensor (Switch)

LOW 12 'Turn Off Left Led
LOW 13 'Turn Off Right Led

IF IN14=0 THEN bk_right: 'Check Colision Switch R
IF IN15=0 THEN bk_left: 'Check Colision Switch L
GOTO forward1

forward1:
OUTA = %1001
GOTO bumper1

bk_right:
OUTA = %0110
HIGH 12
PAUSE 1200
FREQOUT spk,600,1042,2204 'c4,db5
FREQOUT spk,600,1389,2632 'f4,e5
OUTA = %0101
PAUSE 1000
GOTO bumper1

bk_left:
OUTA = %0110
HIGH 13
PAUSE 1200
FREQOUT spk,600,1042,2204 'c4,db5
FREQOUT spk,600,1389,2632 'f4,e5
OUTA = %1010
PAUSE 1000
GOTO bumper1

'---------- Program Sound ---------------------------------------------------------------
' Constants (Notes and their frequencies).

G1 CON 195 'Low notes
Ab1 CON 207
A1 CON 220
Bb1 CON 234
BE1 CON 248
C2 CON 262

G3 CON 781
Ab3 CON 829

A3 CON 877
Bb3 CON 928
BE3 CON 980

C4 CON 1042 'High notes
G4 CON 1563
Ab4 CON 1658
A4 CON 1754
Bb4 CON 1856
BE4 CON 1960


C5 CON 2084 'Very high notes
D5 CON 2326


G5 CON 3136
Ab5 CON 3729
Bb5 CON 3951
CS5 CON 2218
Irfreq CON 27036

'---------- adamsFamily Music ----------------------------

SOUND1:

HIGH 12
HIGH 13
FOR notes = 0 TO 3
LOOKUP notes,[G4,A4,BE4,C5],frequency
FREQOUT 11,295,frequency
NEXT
PAUSE 395
FREQOUT 11,350,frequency
PAUSE 395
FREQOUT 11,350,frequency
PAUSE 395
FOR notes = 0 TO 3
LOOKUP notes,[A4,BE4,C5,D5],frequency
FREQOUT 11,295,frequency
NEXT
PAUSE 1500
FOR notes = 0 TO 3
LOOKUP notes,[A4,BE4,C5,D5],frequency
FREQOUT 11,295,frequency
NEXT
PAUSE 395
FOR notes = 0 TO 3
LOOKUP notes,[A4,BE4,C5,D5],frequency
FREQOUT 11,295,frequency
NEXT
PAUSE 395
FOR notes = 0 TO 3
LOOKUP notes,[G4,A4,BE4,C5],frequency
FREQOUT 11,295,frequency
NEXT
PAUSE 395
FREQOUT 11,350,frequency
PAUSE 395
FREQOUT 11,350,frequency
'pause 5000
LOW 12
LOW 13
GOTO menu3
'---------------------------------------

'SOUND2
'freqout spk,100,2042,3204 'c4,db5
'freqout spk,200,2389,3632 'f4,e5
'pause 1500
'goto menu3


'---------- Programs Infrared Sensor ----------------------------------------------------

IRPD1:

PAUSE 50 'delay so you can read
'screen. remove after test
LOW 12
LOW 13

HIGH 4 : PAUSE 1
LOW 4 : PAUSE 1
HIGH 4 : PAUSE 1
tempr = IN6
LOW 4

HIGH 5 : PAUSE 1
LOW 5 : PAUSE 1
HIGH 5 : PAUSE 1
templ = IN6
LOW 5

action = 0
IF templ=1 THEN cont1 'If 1 then nothing
action = action + 1 'is on the left.
cont1:
IF tempr=1 THEN cont2 'If 1 then nothing
action = action + 2 'is on the right.
cont2:

'action = 0, nothing in the way
'action = 1, something in front of left side
'action = 2, something in front of right side
'action = 3, something in front of both sides

BRANCH action,[forward,right,left,backup]
GOTO start


forward:
OUTA = %1001
LOW 12
LOW 13
GOTO irpd1

right: 'Hit on left
OUTA = %0101
HIGH 12
GOTO irpd1

left: 'Hit on right
OUTA = %1010
HIGH 13
GOTO irpd1

backup:
OUTA = %0110
HIGH 12
HIGH 13
PAUSE 1300
FREQOUT spk,600,1042,2204 'c4,db5
FREQOUT spk,600,1389,2632 'f4,e5
OUTA = %1010
PAUSE 900
GOTO irpd1


'---------- Program Mini Remote Control -------------------------------------------

rc1:

IF IN10=0 THEN right2: 'Check Colision Switch RC Right
IF IN9=0 THEN left2: 'Check Colision Switch RC Left
IF IN8=0 THEN backup2: 'Check Colision Switch RC Down
IF IN7=0 THEN forward2: 'Check Colision Switch RC Up

GOTO stop1

forward2:
DEBUG HOME, " Remote FORWARD "
OUTA = %1001
GOTO rc1

backup2:
DEBUG HOME, " Remote BACKWARD "
HIGH 12
HIGH 13
OUTA = %0110
GOTO rc1

right2:
DEBUG HOME, " Remote RIGHT "
HIGH 13
OUTA = %0101
GOTO rc1

left2:
DEBUG HOME, " Remote LEFT "
HIGH 12
OUTA = %1010
GOTO rc1

stop1:
DEBUG HOME, " Remote STOP "
OUTA = %0000
LOW 12
LOW 13
GOTO rc1


'---------- Program Tracker Line Sensor ----------------------------

LTRACK1:

INPUT 4 'Left Tracker Output
INPUT 5 'Right Tracker Output
INPUT 6 'Center Tracker Output

error_level VAR Word
'left_sensor6 var word
'right_sensor6 var word
'middle_sensor6
LOW 1
LOW 2
LOW 3

error_level = 3
start6:
IF IN4 = 0 THEN left6
IF IN5 = 0 THEN right6
IF IN6 = 0 THEN forward6
IF error_level = 1 THEN right6
IF error_level = 2 THEN left6
IF error_level = 3 THEN forward6
GOTO start6

forward6:
error_level = 3
DEBUG "go forward6 ",CR 'remove after testing
DEBUG " ",CR
OUTA = %1001
HIGH 12 'turn left LED off
HIGH 13 'turn right LED off
GOTO start6

right6:
error_level = 1
DEBUG "go right6 ",CR 'remove after testing
DEBUG " ",CR
OUTA = %1010
HIGH 13 'turn left LED on
LOW 12 'turn right LED off
GOTO start6

left6:
error_level = 2
DEBUG "go left6 ",CR 'remove after testing
DEBUG " ",CR
OUTA = %0101
HIGH 12 'turn right LED on
LOW 13 'turn left LED off
GOTO start6

'-----------------------------------------------------------------


จากคุณ : สุรเชษฐ์ -[ 8 ก.พ. 49 - 21:27:04 A:221.128.78.115 X:221.128.78.122 ]





กระทู้ยอดนิยม