Example program in Chapter 10 of "What's a Microcontroller?" book
jeffrey morris
Posts: 52
There is an example program on page 287 in the book. Is it possible to·put the "read_?" subroutines ·in loops and put debugin code from get_request subroutines in each loop?
Comments
·· I looked at the code you refer to, but I don't understand what you're trying to do.· Why don't you post the code as you are thinking, and we can tell you if it will work that way.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
'{$PBASIC 2.5}
pb1pin PIN 3
pb2pin PIN 4
potpin PIN 7
photopin PIN 9
delayrc CON 100
delayreader CON 250
request1 VAR Nib
request2 VAR Nib
time VAR Word
DO
GOSUB display_menu
GOSUB get_request
ON request1 GOSUB read_pb1,read_pb2,read_pot,read_photo
LOOP
display_menu:
DEBUG CLS,"MENU:",CR,CR,
"1) Pushbutton 1",CR,
"2) Pushbutton 2",CR,
"3) Potentiometer",CR,
"4) Photoresistor",CR,CR
RETURN
get_request:
DEBUGIN DEC1 request1
request1 = request1 - 1
RETURN
read_pb1:
DO
DEBUG HOME,? pb1pin
PAUSE delayreader
DEBUGIN DEC1 request2
request2 = request2 - 1
IF (request2 = 4) THEN EXIT
LOOP
RETURN
read_pb2:
DO
DEBUG HOME,? pb2pin
PAUSE delayreader
DEBUGIN DEC1 request2
request2 = request2 - 1
IF (request2 = 4) THEN EXIT
LOOP
RETURN
read_pot:
DO
HIGH potpin
PAUSE delayrc
RCTIME potpin,1,time
DEBUG HOME,time," "
PAUSE delayreader
DEBUGIN DEC1 request2
request2 = request2 - 1
IF (request2 = 4) THEN EXIT
LOOP
RETURN
read_photo:
DO
HIGH photopin
PAUSE delayrc
RCTIME photopin,1,time
DEBUG HOME,time," "
PAUSE delayreader
DEBUGIN DEC1 request2
request2 = request2 - 1
IF (request2 = 4) THEN EXIT
LOOP
RETURN
·· Your code looks like it should work fine.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
'{$STAMP BS2}
'{$PBASIC 2.5}
pb1pin PIN 3
pb2pin PIN 4
potpin PIN 7
photopin PIN 9
delayrc CON 100
delayreader CON 250
time1 VAR Word
time2 VAR Word
DEBUG HOME
DO
HIGH potpin
HIGH photopin
PAUSE delayrc
RCTIME potpin,1,time1
RCTIME photopin,1,time2
DEBUG CRSRXY,0,0,"Pushbutton 1 = ",DEC1 pb1pin,CR
DEBUG CRSRXY,0,1,"Pushbutton 2 = ",DEC1 pb2pin,CR
DEBUG CRSRXY,0,2,"Potentiometer = ",DEC5 time1,CR
DEBUG CRSRXY,0,3,"Photoresistor = ",DEC5 time2,CR
PAUSE delayreader
LOOP
·· The DEBUGIN is waiting for input from the DEBUG Terminal input window at top.· You have to click in there and type a number from 1 - 4.· In the other code there is no DEBUGIN, so my guess is that's it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com