PDA

View Full Version : Elevator Controls



M. Wilson
08-18-2008, 06:49 AM
Hi everybody:
ˇˇˇˇˇˇ I am having problems putting together the servo controls and the push button controls. Separately they work fine.ˇ However when I put them together the servo will not work.ˇ I built the servo from figure 4-21, page 130 of the "What's a microcontroller?" book.ˇ I think the out put from the push button controls, P-15 (pg. 1) must be linked to the servo input before the servo will take commands.ˇ When P-15 (pg.1) goes high it shouldˇcause the servo to rotate cwˇ180 degrees, pause seven seconds, then rotate 180 degrees.

I would appreciate any help you can give me.

M. Wilson

Franklin
08-18-2008, 08:29 AM
OK, point 1, when you attach code please use the Attachment Manager and attach the real code you are using. For me, looking at bad pictures of code does me no good. Sorry

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

SRLM
08-18-2008, 01:11 PM
Did you take a picture of a printout? You could have saved the ink by just taking a screen shot. Also, you can just link or refer to the page in the book: anybody can access it so no need to worry about getting out the right page. Anyway, the best way to attach code is to use the source file.

Second: what exactly is your project?

M. Wilson
08-19-2008, 01:39 AM
sorry I attached it wrong...

I am working on modelˇElevator controls

Here's a better attachment. The servo controls I used is located on page 130 of "What's a Microcontroller" Book

SRLM
08-19-2008, 02:53 AM
First off, you should replace all you pin numbers with names. This is easy: just declare it at the begining. It will help everyone understand your code.

button PIN 15
LED PIN 16
'etc



Next up is lines 69 to 71 (the loop.) You have it set so that it loops 7 thousand times. Bad idea. You can just insert a PAUSE 7000 to make it idle for seven seconds. Same idea at 83 to 85.

Now that I've covered that, might I add that the code will *never* reach that section since it is preceeded by a DO-LOOP with no possibility of escape. Your best bet would be to place the servo stuff in a method, that you then call with GOSUB. You then call the method after testing for the button. You also don't need the LOW 14 at line 45 since that is your servo line. Final note: use comments! I have no idea what all that stuff in the DO-LOOP is supposed to do, and your code is no help. It looks like you test a bunch of things, but why? What are the preconditions and post condidtions? Comments are an essential part of all programming.