Shop OBEX P1 Docs P2 Docs Learn Events
"What''s a Microcontroller" Chapter 4 project 1 — Parallax Forums

"What''s a Microcontroller" Chapter 4 project 1

ArchiverArchiver Posts: 46,084
edited 2004-02-05 06:26 in General Discussion
Hello All,

I am brand new to using microcontrollers and recently picked up the
Basic Stamp kit at Radio Shack. I have been having a blast ever
since and have made my way through all the chapters, exercises and
projects with no problems up to Chapter 4 Project 1 in the "What's a
Microcontroller" educational book.

The project asks that I modify an earlier project so that it
monitors a kill switch. When then kill switch (a pushbutton
connected to P4) is being pressed the Debug Terminal should not
accept any commands. It should also display this message: "Press
Start switch to start machinery". When the start switch (pushbutton
connect to P1) is pressed, the program will function normally, like
it does when I ran my earlier project. If power is disconnected and
reconnected, the program should behave as though the kill switch has
been pressed.

Here is what I came up with. I will include a copy of the code from
the earlier project and then the code for this project. Would some
of you more experienced with stamps and PBASIC 2.5 look over it for
me and let me know if there is a better way to achieve this. I am
looking for some constructive critisism and help to aid me in my
self study program.

Original code from earlier project:

' What's a Microcontroller - Ch04ServoControlWithDebugYourTurn.bs2
' Use the Basic Stamp to control servo movement!
' Adjust position and hold time using debug terminal!

'{$STAMP BS2}
'{$PBASIC 2.5}

counter VAR Word
pulses VAR Word
duration VAR Word

DO

DEBUG CLS, "Enter the number of pulses:", CR
DEBUGIN DEC pulses

DO
DEBUG "Enter PULSOUT duration:", CR
DEBUGIN DEC duration
IF duration < 350 THEN
DEBUG "Value of duration must be above 349", CR
PAUSE 1000
ENDIF
IF duration > 1150 THEN
DEBUG "Value of duration must be less then 1151",CR
PAUSE 1000
ENDIF
LOOP UNTIL duration > 349 AND duration < 1151


DEBUG "Servo is running ...", CR

FOR counter = 1 TO pulses
PULSOUT 14, duration
PAUSE 20
NEXT

DEBUG "That's all Folks!"
PAUSE 1000

FOR counter = 1 TO 20
PULSOUT 14, 750
PAUSE 20
NEXT

LOOP

******************************


Modified code for end of Chapter 4 Project 1:

' What's a Microcontroller - Ch04ServoControlWithDebugProject1.bs2
' Use the Basic Stamp to control servo movement!
' Adjust position and hold time using debug terminal!
' Ability to monitor a kill switch and resume with a start switch!

'{$STAMP BS2}
'{$PBASIC 2.5}

counter VAR Word
pulses VAR Word
duration VAR Word

DO

DO WHILE IN0 = 0
DEBUG "Press Start switch to start the machinery",CR, CRSRUP
LOOP

DO
DEBUG CLS, "Enter the number of pulses:", CR
DEBUGIN DEC pulses

DO
DEBUG "Enter PULSOUT duration:", CR
DEBUGIN DEC duration
IF duration < 350 THEN
DEBUG "Value of duration must be above 349", CR
PAUSE 1000
ENDIF
IF duration > 1150 THEN
DEBUG "Value of duration must be less then 1151",CR
PAUSE 1000
ENDIF
LOOP UNTIL duration > 349 AND duration < 1151

DEBUG "Servo is running ...", CR

FOR counter = 1 TO pulses
PULSOUT 14, duration
PAUSE 20
NEXT

DEBUG "That's all Folks!"
PAUSE 1000

FOR counter = 1 TO 20
PULSOUT 14, 750
PAUSE 20
NEXT
LOOP UNTIL IN4 = 1

DEBUG CLS

LOOP

***********************


Any help you can provide will be greatly appreciated!

Lu Kwan
Sign In or Register to comment.