Shop OBEX P1 Docs P2 Docs Learn Events
need guidance — Parallax Forums

need guidance

Jose AAGJose AAG Posts: 5
edited 2006-06-23 16:07 in BASIC Stamp
I have programed a few PlCs but now my boss wants to create our own controller, can some one help me write a little program just an input and an output ( when the input is made the output should make)· I'm using a Stamp1 project board. I'v been reading for two days and have tried a few of the included samples but since I have no experience in basic is a little dificult. Thanks in advance for any help.

Comments

  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-06-22 20:05
    What are you trying to do with the input & output?

    For example, if you press a button (input), an LED will blink (output)...
  • Jose AAGJose AAG Posts: 5
    edited 2006-06-22 20:10
    that's exactly what i'm trying to do Kevin i belive that's a good start just press the button ( input P0) turn led on (output P4) release button led should go out.

    Thanks
  • Mike GreenMike Green Posts: 23,101
    edited 2006-06-22 20:19
    Assuming that when you press the button, you connect P0 to ground (Vss) and that the LED is connected from P4 to Vcc via a resistor to limit current:

    Wait:
    if Pin0 = 1 then Wait
    Blink:
    Pin4 = 0
    pause 250
    Pin4 = 1
    pause 250
    if Pin0 = 1 then Blink
    goto Wait
  • Mike GreenMike Green Posts: 23,101
    edited 2006-06-22 20:20
    I forgot to initialize the pins. Put the following first:

    Dir0 = 0
    Dir4 = 1
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-06-22 20:40
    Jose,

    I don't have BS1 experience, but can tell you that starting off with a BS2 would be much easier. It uses improved PBasic syntax, and there is more info available.

    Take a look at the "What's a Microcontroller" manual, which can be downloaded for free. Chapter three describes doing what you are trying to do, the caveat being that the code is written for the BS2, not the BS1.

    A good way to get started with a BS2 is the Summer Special, also known as the RadioShack "What's a Microcontroller" Kit.

    But if you are limited to the BS1, keep posting, there are plenty of people here than can help.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-06-22 20:41
    Mike -

    I suspect you need a pull-up resistor on P0, don't you?

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Jose AAGJose AAG Posts: 5
    edited 2006-06-22 20:49
    Bruce by a pull-up resistor do you mean a 470 ohm resistor ( should that be·connected this way? Vss-to-switch-to-resistor-to-P0)
    thanks for the fast responses guys.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-06-22 20:58
    Not quite. The pull-up resistor (4.7K to 10K usually) is connected from P0 to Vcc (5V). The switch is connected from P0 to Vss (Ground). The idea is that the pull-up holds the pin at a high level (Vcc) unless the switch is closed. Then the pin is at a low level (ground). The resistor is chosen to limit the amount of current through the switch when it is closed (to 0.5 to 1 ma). The resistor could be larger, but is rarely more than 100K.

    You can also have a pull-down resistor with the switch connected from the pin to Vcc, but most sensors and switches are meant to connect a signal line to ground since the ground can also serve as a shield.
  • Jose AAGJose AAG Posts: 5
    edited 2006-06-22 21:48
    this is what I have and is not working
    Vss to Sw to P0
    Vdd to 10k to P0
    LED Short leg to P4, long leg to 470 ohm- to Vdd and apply the following code

    Dir0 = 0
    Dir4 = 1

    Wait:
    if Pin0 = 1 then Wait
    Blink:
    Pin4 = 0
    pause 250
    Pin4 = 1
    pause 250
    if Pin0 = 1 then Blink
    goto Wait

    As soon as I power up LED blink but when sw makes (closes) Led stops blinking

    Post Edited (Jose AAG) : 6/22/2006 9:52:36 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-06-23 01:50
    Then it sounds like your switch is "normally closed", and is immediately providing a
    'zero' to Pin0. When you press it, it 'opens', and lets the pin float.

    So, change the "IF Pin0 = 1" to "IF Pin0 = 0".
  • Jose AAGJose AAG Posts: 5
    edited 2006-06-23 16:07
    It's working smile.gif· seems that the code was·wrong, one of the " if Pin0 =·# then Wait" was supposed to be a "0" and the other a "1"

    Thanks to all of you, I'll keep on playing with it.
Sign In or Register to comment.