kicknitinkc
04-15-2010, 10:43 AM
I am using the 5v regulated power supply from the board of education. A 9v battery is connected to the board. Here is my code, it is for a mechatronics project that I can't yet give all the details on. Most of the constants stuff is for the speakjet. All I am doing with this program right now is making sure I have the speakjet and amp working properly, which appears to be the case. I'm almost positive it has something to do with the BS2 now because when the speakjet/speaker stops playing sounds, my computer can't find the BS2 when I try to reload the program.
' {$STAMP BS2}
' {$PBASIC 2.5}
#SELECT $stamp
#CASE BS2, BS2E, BS2PE
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
#CASE BS2SX, BS2P
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
#ENDSELECT
Inverted CON $4000
Baud CON T9600
PA0 CON 0 ' pauses
PA1 CON 1
PA2 CON 2
PA3 CON 3
PA4 CON 4
PA5 CON 5
PA6 CON 6
Fast CON 7
Slow CON 8
Stress CON 14
Relax CON 15
_Wait CON 16 ' note underscore
Soft CON 18
Volume CON 20
Speed CON 21
Pitch CON 22
Bend CON 23
PortCtr CON 24
Port CON 25
Repeat CON 26
CallPhr CON 28
GotoPhr CON 29
Delay CON 30
Reset CON 31
IY CON 128
IH CON 129
EY CON 130
EH CON 131
AY CON 132
AX CON 133
UX CON 134
OH CON 135
AW CON 136
OW CON 137
UH CON 138
UW CON 139
MM CON 140
NE CON 141
NO CON 142
NGE CON 143
NGO CON 144
LE CON 145
LO CON 146
WW CON 147
RR CON 148
IYRR CON 149
EYRR CON 150
AXRR CON 151
AWRR CON 152
OWRR CON 153
EYIY CON 154
OHIY CON 155
OWIY CON 156
OHIH CON 157
IYEH CON 158
EHLL CON 159
IYUW CON 160
AXUW CON 161
IHWW CON 162
AYWW CON 163
OWWW CON 164
JH CON 165
VV CON 166
ZZ CON 167
ZH CON 168
DH CON 169
BE CON 170
BO CON 171
EB CON 172
OB CON 173
DE CON 174
_DO CON 175 ' note underscore
ED CON 176
OD CON 177
GE CON 178
GO CON 179
EG CON 180
OG CON 181
CH CON 182
HE CON 183
HO CON 184
WH CON 185
FF CON 186
SE CON 187
SO CON 188
SH CON 189
TH CON 190
TT CON 191
TU CON 192
TS CON 193
KE CON 194
KO CON 195
EK CON 196
OK CON 197
PE CON 198
PO CON 199
RO CON 200
R1 CON 201
R2 CON 202
R3 CON 203
R4 CON 204
R5 CON 205
R6 CON 206
R7 CON 207
R8 CON 208
R9 CON 209
A0 CON 210
A1 CON 211
A2 CON 212
A3 CON 213
A4 CON 214
A5 CON 215
A6 CON 216
A7 CON 217
A8 CON 218
A9 CON 219
_B0 CON 220 ' note underscore
_B1 CON 221
_B2 CON 222
_B3 CON 223
_B4 CON 224
_B5 CON 225
_B6 CON 226
_B7 CON 227
_B8 CON 228
_B9 CON 229
C0 CON 230
C1 CON 231
C2 CON 232
C3 CON 233
C4 CON 234
C5 CON 235
C6 CON 236
C7 CON 237
C8 CON 238
C9 CON 239
D0 CON 240 ' DTMF tones
D1 CON 241
D2 CON 242
D3 CON 243
D4 CON 244
D5 CON 245
D6 CON 246
D7 CON 247
D8 CON 248
D9 CON 249
D10 CON 250
D11 CON 251
M0 CON 252 ' sonar pin
M1 CON 253 ' pistol shot
M2 CON 254 ' WOW
EOS CON 255 ' end of string
' -----[ Variables ]-------------------------------------------------------
eeAddr VAR Word ' address of speech element
element VAR Byte ' speech element / code
idx VAR Word
tx PIN 15
rdy PIN 4
DO
'ONE VOLT
SEROUT TX, $0054, [WW,UX,NO,VV,OW,LO,TT]
'ANOTHER NAIL IN YOUR COFFIN
SEROUT tx, $0054, [21,110,M1,M1,M1,21,110,UX,22,105,NO,21,100,22,110, UX,21,127,22, 100,TH,AXRR,0,21,120,ne,eyiy,LO,0,IH,NO,0,21,125,I YUW,OWRR,0,21,110,KE,AW,FF,IH,NE]
'SAM
SEROUT tx, $0054, [20,127,188, 22, 174,21,25,22,180,132,140]
PAUSE 5000
LOOP
kicknitinkc
05-07-2010, 07:25 AM
Well I got my project pretty much finished. Its a cigarette dispenser that talks trash to the user and stores data about how much cigarettes they smoke and how much money they spend on them. My original plans were to use infrared for light detection but I couldn't get it working right so I used a red LED to give the phototransistor enough light to detect a break in the beam from a cigarette being dispensed. There are two pushbuttons. One is used to reset the EEPROM data and the other is supposed to display (# of cigarettes) when the user holds it down. I have already presented my project but would like to eventually make it better. I have a few questions: 1. I had the "money spent" data displaying the dollars and cents to the nearest quarter correctly last night but now it counts up in increments of 50 cents and the dollar value doesn't always add to the next digit. I have no idea what I changed to mess it up, any ideas? 2. How can I set my light detection with IR and have it fast enough to notice a quick break in the beam of light? I used the infrared receiver but it didn't seem to detect very well in small areas (3 inch gap) so I switched to using RCtime with a phototransistor and an IR LED. The phototransistor wouldnt pick up the infrared light for anything. I messed around a little with the infrared transistor that Parallax sells but had no luck. 3. What is the best way to use my button2 command so I can get the LCD to display "# of cigarettes" when the user holds down button 2? Thanks,
Sam
here's the code if you don't want to download it:
' {$STAMP BS2e}
' {$PBASIC 2.5}
#SELECT $stamp
#CASE BS2, BS2E, BS2PE
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
#CASE BS2SX, BS2P
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
#ENDSELECT
Inverted CON $4000
Baud CON T9600
PA0 CON 0 ' pauses
PA1 CON 1
PA2 CON 2
PA3 CON 3
PA4 CON 4
PA5 CON 5
PA6 CON 6
Fast CON 7
Slow CON 8
Stress CON 14
Relax CON 15
_Wait CON 16 ' note underscore
Soft CON 18
Volume CON 20
Speed CON 21
Pitch CON 22
Bend CON 23
PortCtr CON 24
Port CON 25
Repeat CON 26
CallPhr CON 28
GotoPhr CON 29
Delay CON 30
Reset CON 31
IY CON 128
IH CON 129
EY CON 130
EH CON 131
AY CON 132
AX CON 133
UX CON 134
OH CON 135
AW CON 136
OW CON 137
UH CON 138
UW CON 139
MM CON 140
NE CON 141
NO CON 142
NGE CON 143
NGO CON 144
LE CON 145
LO CON 146
WW CON 147
RR CON 148
IYRR CON 149
EYRR CON 150
AXRR CON 151
AWRR CON 152
OWRR CON 153
EYIY CON 154
OHIY CON 155
OWIY CON 156
OHIH CON 157
IYEH CON 158
EHLL CON 159
IYUW CON 160
AXUW CON 161
IHWW CON 162
AYWW CON 163
OWWW CON 164
JH CON 165
VV CON 166
ZZ CON 167
ZH CON 168
DH CON 169
BE CON 170
BO CON 171
EB CON 172
OB CON 173
DE CON 174
_DO CON 175 ' note underscore
ED CON 176
OD CON 177
GE CON 178
GO CON 179
EG CON 180
OG CON 181
CH CON 182
HE CON 183
HO CON 184
WH CON 185
FF CON 186
SE CON 187
SO CON 188
SH CON 189
TH CON 190
TT CON 191
TU CON 192
TS CON 193
KE CON 194
KO CON 195
EK CON 196
OK CON 197
PE CON 198
PO CON 199
RO CON 200
R1 CON 201
R2 CON 202
R3 CON 203
R4 CON 204
R5 CON 205
R6 CON 206
R7 CON 207
R8 CON 208
R9 CON 209
A0 CON 210
A1 CON 211
A2 CON 212
A3 CON 213
A4 CON 214
A5 CON 215
A6 CON 216
A7 CON 217
A8 CON 218
A9 CON 219
_B0 CON 220 ' note underscore
_B1 CON 221
_B2 CON 222
_B3 CON 223
_B4 CON 224
_B5 CON 225
_B6 CON 226
_B7 CON 227
_B8 CON 228
_B9 CON 229
C0 CON 230
C1 CON 231
C2 CON 232
C3 CON 233
C4 CON 234
C5 CON 235
C6 CON 236
C7 CON 237
C8 CON 238
C9 CON 239
D0 CON 240 ' DTMF tones
D1 CON 241
D2 CON 242
D3 CON 243
D4 CON 244
D5 CON 245
D6 CON 246
D7 CON 247
D8 CON 248
D9 CON 249
D10 CON 250
D11 CON 251
M0 CON 252 ' sonar pin
M1 CON 253 ' pistol shot
M2 CON 254 ' WOW
EOS CON 255 ' end of string
button1 PIN 0 ' button pin
button2 PIN 2
lcdTX PIN 3 ' serial output to LCD
LcdBaud CON 32 ' LCD baudrate = 19,200
LcdCls CON $0C ' clear LCD (use PAUSE 5 after)
LcdBLon CON $11 ' backlight on
LcdBLoff CON $12 ' backlight off
LcdOff CON $15 ' LCD off
LcdOn1 CON $16 ' LCD on; cursor off, blink off
LcdCC0 CON $F8 ' define custom char 0
LcdCC1 CON $F9 ' define custom char 1
LcdCC2 CON $FA ' define custom char 2
LcdLine1 CON $80 ' move to line 1, column 0
LcdLine2 CON $94 ' move to line 2, column 0
PhotoCircuit PIN 1
' -----[ Variables ]-------------------------------------------------------
' -----[ Variables ]-------------------------------------------------------
eeAddr VAR Word ' address of speech element
element VAR Byte ' speech element / code
PhotoVal VAR Word
calibrate VAR Word
COUNTER VAR Byte
TABLEIDX VAR Byte
PHRASE VAR Byte
dollar VAR Byte
cents VAR Byte
tx PIN 15
rdy PIN 14
'speakjet phrases
SHOT DATA ro,r1,r2,r3,r2,r1,ro, eos
COFFIN DATA 21,110,M1,M1,M1,21,110,UX,22,105,NO,21,100,22,110, UX,21,127,22, 100,TH,AXRR,0,21,120,ne,eyiy,LO,0,IH,NO,0,21,125,I YUW,OWRR,0,21,110,KE,AW,FF,IH,NE, EOS
ANOTHER DATA SO,MM,OW,EK,UX,NO,UX,TH,AXRR,WW,UX,NO,EOS
KILLING DATA IYUW,FAST,OwRr,KE,FAST,IH,FAST,LO,FAST,LE,FAST,IY, NGE,IYUW,FAST,OWRR,SO,EH,LO,FF,SE,SLOW,AY,MM,EOS
ASHTRAY DATA IYUW,SO,MM,EH,LO,LE,OHIH,OK,AY,NO,AY,SH,TU,RR,EYIY ,EOS
SMOKING DATA SE,TU,AW,PO,SE,MM,OW,KE,IY,NGO,TH,AY,TU,KE,RR,AY,P O,EOS
DIE DATA 22,50,IYUW,DE,OW,NO,TU,AW,LE,WW,FAST,EYIY,SO,DE,OH IH,FF,RR,UX,MM,TU,UX,SLOW,BE,SLOW,AY,KE,SLOW,OW,OW ,OW,OW,OW,OW,EOS
BIOTCH DATA 22,75,MM,MM,MM,MM,WW,UX,TU,IYUW,WW,UX,NO,TU,PA5,BE ,IY,AW,AW,AW,TU,CH,EOS
'display data with intro message
PAUSE 1000
READ 0, counter
cents = ((counter) // 4)*25
READ 1, dollar
SEROUT Tx, Baud, [21,120,20,127,22,200,he,eh,eh,le,le,lo,ow,ow,ow,SE ,AY,AY,AY,MM,PA2,WW,UH,LO,DE,IYUW,LE,OHIH,KO,EYIY, KE,AY,NO,SE,AXRR,SE,TU,IH,OK,eos ]
SEROUT lcdtx,lcdbaud, [lcdblon,(lcdline1), " Money Spent",(lcdline2)," $",DEC dollar,".",DEC2 cents]
HIGH PhotoCircuit ' Set to output
PAUSE 3 ' Pause for 3 ms to charge
RCTIME PhotoCircuit,1,PhotoVal 'measure rctime
calibrate = photoval 'calibrate light setting before starting
DO
IF button1 = 0 THEN 'if button is pressed, reset data
WRITE 0,0
READ 0, counter
WRITE 1,0
READ 1, dollar
'display zeros on LCD
SEROUT lcdTX, LcdBaud, [lcdblon,(lcdline1), " Money Spent",(lcdline2)," $","0",".","00"]
ENDIF
'DEBUG ? button2
'IF button2 = 0 THEN
'SEROUT lcdTX, LcdBaud, [(lcdline1),"# of Cigarettes",(lcdline2)," ",DEC counter]
'ENDIF
GOSUB charge
GOSUB detect
LOOP
charge:
' Measure RC time
HIGH PhotoCircuit ' Set to output
PAUSE 3 ' Pause for 3 ms to charge
RCTIME PhotoCircuit,1,PhotoVal ' measure rctime
detect:
DEBUG HOME, DEC4 photoval ,CR, DEC4 calibrate,CR, DEC3 COUNTER
IF photoval > calibrate + 125 THEN
SEROUT lcdtx, lcdbaud, [lcdcls,lcdblon]
'SEROUT lcdTX, LcdBaud, [(lcdline1),"# of Cigarretes",(lcdline2),DEC counter]
cents = ((counter+1) // 4)*25 'create decimal place for cents
'LCD: display money spent on cigarretes
SEROUT lcdTX, LcdBaud, [(lcdline1), " Money Spent",(lcdline2)," $",DEC dollar,".",DEC2 cents]
'Set volume and pitch for speakjet
SEROUT Tx\RDY,84,[volume,127,pitch,100]
'lookup phrase
LOOKUP TABLEIDX, [SHOT, COFFIN,ANOTHER,KILLING,ASHTRAY,SMOKING, DIE, BIOTCH ], PHRASE
'set address to phrase
eeAddr = PHRASE
'play phrase
GOSUB Play_String
PAUSE 1000
'math to hold dollars place
IF cents = 75 THEN
dollar = dollar + 1
ENDIF
'update counter
COUNTER = COUNTER + 1
'write values to eeprom for storage
WRITE 0 , counter
WRITE 1 , dollar
ENDIF
RETURN
Play_String:
'run a loop to play phrase and exit at end of phrase
DO
READ eeAddr, element ' get phrase element from eeprom
eeAddr = eeAddr + 1 ' point to next
IF (element = EOS) THEN EXIT ' end? if yes we're done
SEROUT Tx, Baud, [element] ' send element to SpeakJet
LOOP
'get ready to play next phrase
TABLEIDX = TABLEIDX + 1
'if at end of table go to beginning
IF TABLEIDX = 9 THEN
TABLEIDX = 0
ENDIF
RETURN
Post Edited (kicknitinkc) : 5/7/2010 2:50:06 AM GMT