BS2PX如何讓SRF02動作
我有找到SRF08的程式,要如何改為SRF02'{$STAMP BS2px}
' {$PBASIC 2.5}
'***********************************************************
'** **
'** I2C Routines for the Basic Stamp BS2p **
'** Controlling SP03 Speech Synthesizer **
'** **
'** Copyright 2002 - Devantech Ltd **
'** Commercial use of this software is prohibited **
'** Private and educational use only is permitted **
'** **
'** Written by Gerald Coe - August 2002 **
'** **
'***********************************************************
SCL CON 10 ' I2C clock
SDA CON 9 ' I2C data
NOP CON 0 ' No Operation command
status VARByte
Main:
' The following shows how easy it is to use the BS2p with the Speech Module,
' a single line command is all that is required to speak any of the 30
' pre-loaded phrases. The example below shows how to speak phrase number 21.
GOSUB wait4shutup ' wait for last phrase to finish speaking
I2COUT SDA, $C4, 0, ' speak phrase number 21 and flush internal buffer
' You can also send your own Text to Speech messages to the module to be spoken.
' The first data byte is the command, in this case a NOP, since we just need to
' load the buffer. The 2nd value is Volume (0-7) which works backwards - 0 is
' loudest and 7 is quiet. The 3rd value is Pitch (0-7) which it is best to just
' try it and see. The 4th value is Speed (0-3) with 3 being fastest.
' You then place the text you wish spoken in inverted comma's and finally
' the 0 (NULL).
GOSUB wait4shutup ' wait for last phrase to finish speaking
I2COUT SDA, $C4, 0,
' The above loads the modules internal buffer. You then need to send a command to
' speak the phrase you just loaded.
I2COUT SDA, $C4, 0, [$40] ' The speak command also flushes the buffer
' You can also load the buffer in smaller, multiple fragments if you wish to.
' Up to 85 bytes can be stored in the SP03's internal buffer, that's 81 characters
' plus the Volume, Pitch, Speed and terminating NULL.
GOSUB wait4shutup ' wait for last phrase to finish speaking
I2COUT SDA, $C4, 0,
I2COUT SDA, $C4, 0,
I2COUT SDA, $C4, 0,
I2COUT SDA, $C4, 0, [$40] ' Speak the phrase.
' And thats it.
' The following completes the program so that you can run it.
forever:'GOTO forever
wait4shutup:
I2CIN SDA, $C4, 0,
'DEBUG "Status:",DEC status,CR
IF status>0 THEN wait4shutup
RETURN 對, 使用BS2PX只要用 一行指令 I2Cout 或是 I2Cin 就可以對任何I2C裝置收發資料。
要注意: $C4是指I2C裝置的位置 (每個裝置都要事先指定不同的位置) !
頁:
[1]