Shop OBEX P1 Docs P2 Docs Learn Events
Question about switches — Parallax Forums

Question about switches

SomniumSomnium Posts: 46
edited 2006-10-09 21:11 in Propeller 1
I was wondering if I would be able to use this:
www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-1&storeId=10001&catalogId=10001&productId=119010
: with the propeller chip since i have no idea of what I can and can't use with the Propeller.

If yes where can I find code that would allow me to use it. Thanks.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-05 03:50
    You can use just about any contact switch with the Propeller. It works like any switch with a microcontroller. You usually connect the switch between an I/O pin and ground. You connect a resistor (like 10K) between the I/O pin and the Propeller supply voltage (3.3V!). The Propeller reads the I/O pin as high (1) when the switch is open and low (0) when the switch is closed. If the I/O pin is pin 10, you'd write "IF ina[noparse][[/noparse]10] == 0" to test for the switch to be closed. The I/O pins are set to input mode by default.

    Post Edited (Mike Green) : 10/5/2006 4:00:34 AM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2006-10-05 03:54
    Somnium,

    That switch will work just fine. Here is a code example, that will cause LED 16 on the Demo board to "track" the state of the Button.


    [b]CON[/b]
    
    Button = 0        'Input Pin
    {
          ┌─ +3.3V
         ┤
          ┣─ P0
      10k  
          └─ Vss
    }
    
    LEDpin = 16       'Output Pin
    
    
    
    
    [b]PUB[/b] MainLoop
    
        [b]Dira[/b][noparse][[/noparse]Button] := 0           'Make Button pin an INPUT
        [b]Dira[/b][noparse][[/noparse]LEDpin] := 1           'Make LED pin an OUTPUT
    
        [b]repeat[/b]
          [b]Outa[/b][noparse][[/noparse]LEDpin] := [b]Ina[/b][noparse][[/noparse]Button]
    
    
    





    Edit: Mike you beat me to it smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 10/5/2006 3:59:01 AM GMT
  • SomniumSomnium Posts: 46
    edited 2006-10-05 12:53
    Well... I'm using the Propstick... would the code be the same?... and if possible is there a circuit diagram for the code example from Beau Schwabe? thanx
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2006-10-05 15:50
    Somnium,

    The schematic for the button is in the code.· If you are using a Propstick, then a resistor·and LED connected to P16 should work just fine for the code I provided.


                  LED 
    P16 >---/\/\--->|---Vss 
             330
    

              Button
               _|_ 
           o---o o--> +3.3V   
           | 
    P0 >---o
           |
           o--/\/\--> Vss  
              10K 
    


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • SomniumSomnium Posts: 46
    edited 2006-10-07 19:13
    another question... whould "Submini Lever Switch" also work with it? and do I need any other parts to make it work?...

    www.radioshack.com/product/index.jsp?productId=2049718&cp=&origkw=Lever+Switch&kw=lever+switch&parentPage=search
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-07 19:28
    As far as a Stamp or Propeller is concerned, a pushbutton or lever switch or magnetically closed reed relay (for a burglar alarm) or two pieces of wire touched together are all the same. What switch you need depends on your purpose, on mounting location, size, weight, cost, etc. As Beau pointed out, you do need a resistor (roughly 10K, but anything from 4.7K to 47K will do nicely) as he showed in his diagrams.
  • SomniumSomnium Posts: 46
    edited 2006-10-07 20:30
    sorry guys... but I'm having problems with actually setting up the button and LED... I'm still not that gud with the making of schematics...
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-07 21:30
    Download a copy of "What's a Microcontroller?" from the Stamps in Class section of the Parallax website. Most of the circuits in there are directly applicable to the Propeller as long as you substitute 3.3V for the 5V power supply that the Stamps use. Sometimes, like for LEDs, you have to use slightly smaller resistors at the lower voltage, but the LEDs will still work, just look dimmer.
  • SomniumSomnium Posts: 46
    edited 2006-10-09 20:26
    if I wanted to, let's say, send a signal to a servo to move a certain amount how would I go about doing that?... from what I understand all that the switch is doing right now is closing the loop of the circuit and allowing electricity to flow through... which would mean that I'd have to keep the button pressed for the servo to move... any help would be much appreciated... thank you in advance...
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-09 21:11
    Rather than us explaining how to do small variations on similar themes, please download some of the Stamps in Class books and begin to work through the various examples. They are very well described including wiring diagrams with pictures of a breadboard with parts in place, sample Stamp programs, etc. You will learn how to do basic, then more complicated things and should be able to figure out these questions by yourself. We'd be happy to smooth out questions and complications, but the basic concepts are nicely taught in the texts.
Sign In or Register to comment.