Shop OBEX P1 Docs P2 Docs Learn Events
Prop I/O question very basic — Parallax Forums

Prop I/O question very basic

mikedivmikediv Posts: 825
edited 2009-11-21 00:46 in Propeller 1
Hi guys I decided to back up and go the very beginning to learn Spin, please take a look at this code for me..

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'' From Parallax Inc. Propeller Education Kit - 4: I/O and Timing Basics Lab

'' File: ButtonToLed.spin
'' Led mirrors pushbutton state.

PUB ButtonLed ' Pushbutton/Led Method

dira [noparse][[/noparse]6..9] := %1111 ' makes pins outputs
dira [noparse][[/noparse]21..23] := %0000 ' P21-23 → input (this command is redundant)

repeat ' Endless loop

outa [noparse][[/noparse]6..9] := ina [noparse][[/noparse]21..23] ' Copy P21 input to P6 ouput

It works but not how I want it to, I can push each button and it will light up and LED in sequence but what I want it to do is every time I push an input button I wan tit to light up a whole group of pins, so push any button I am using 21-23 and it will turn on prop Pins 6-9 all at the same time ?? Is this possible to do can someone please show me an example. I can even make it simpler.. just use Prop Pin 21 as an input I want to be able to push that button and have it turn on a group of LEDS at the same exact time instead of just one at a time, so push button connected to pin 21 and Prop pins 6,7,8,9 all turn on at the same time ,, thank you

Comments

  • Bill HenningBill Henning Posts: 6,445
    edited 2009-11-19 23:46
    if (ina[noparse][[/noparse]21..23])
       outa[noparse][[/noparse]6..9]~~
    
    



    should do what you want
    mikediv said...
    Hi guys I decided to back up and go the very beginning to learn Spin, please take a look at this code for me..

    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    '' From Parallax Inc. Propeller Education Kit - 4: I/O and Timing Basics Lab

    '' File: ButtonToLed.spin
    '' Led mirrors pushbutton state.

    PUB ButtonLed ' Pushbutton/Led Method

    dira [noparse][[/noparse]6..9] := %1111 ' makes pins outputs
    dira [noparse][[/noparse]21..23] := %0000 ' P21-23 → input (this command is redundant)

    repeat ' Endless loop

    outa [noparse][[/noparse]6..9] := ina [noparse][[/noparse]21..23] ' Copy P21 input to P6 ouput

    It works but not how I want it to, I can push each button and it will light up and LED in sequence but what I want it to do is every time I push an input button I wan tit to light up a whole group of pins, so push any button I am using 21-23 and it will turn on prop Pins 6-9 all at the same time ?? Is this possible to do can someone please show me an example. I can even make it simpler.. just use Prop Pin 21 as an input I want to be able to push that button and have it turn on a group of LEDS at the same exact time instead of just one at a time, so push button connected to pin 21 and Prop pins 6,7,8,9 all turn on at the same time ,, thank you
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
    Morpheusdual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory IO board kit $89.95, both kits $189.95
    Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
    Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
  • mikedivmikediv Posts: 825
    edited 2009-11-19 23:51
    Thank you Bill I am trying it out right now .. I have the prop education labs and fundamentals kit and its very good but it gives you the basic and then kind of leaves you wondering about the more advanced stuff. I never bought the prop manual does that pick up where the educational kit leaves off? every time you guys share examples its always many times more sophisticated than I would write even things like " dira [noparse][[/noparse] 1 ]:= 1 outa [noparse][[/noparse] 1 ]:= 1 you guys would do the same thing but use constants and stuff I don't know about how did you guys learn ??

    Thanks again

    Bill I tired it a few different ways it either turns all the leds on with no action on the push buttons or it does nothing here is one of the ways I tried it

    PUB ButtonLed ' Pushbutton/Led Method

    dira [noparse][[/noparse]4..9] := %111111 ' makes pins outputs
    dira [noparse][[/noparse]16..18] := %000 ' P18-21 → input (this command is redundant)

    if (ina[noparse][[/noparse]16..18])
    outa[noparse][[/noparse]4..9]~~


    repeat ' Endless loop


    Thanks Mike , sometimes it just seems like some people have way more information than me, I am sure part of it is they are pro's and I am a neewb. But there is some very talented people here it gives me programmer envy lol

    Post Edited (mikediv) : 11/20/2009 12:09:49 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-20 00:05
    Read the Propeller Manual. It's downloadable for free. You can also learn a lot by going through other people's code and looking up (in the manual) things that you don't understand.
  • TrapperBobTrapperBob Posts: 142
    edited 2009-11-20 00:13
    The manual for the Propeller is available for free. It can be found in the Propeller Tool help menu as well as on the Parallax website for download.

    ··http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/WebPM-v1.1.pdf

    TrapperBob


    ·
  • nohabnohab Posts: 96
    edited 2009-11-20 16:14
    You have to have the if-section in the endless loop, and you'd better have a else-section too.

    repeat 
      if (ina[noparse][[/noparse]16..18])
        outa[noparse][[/noparse]4..9]~~ 
      else
        outa[noparse][[/noparse]4..9]~
    
  • AribaAriba Posts: 2,690
    edited 2009-11-20 16:52
    This makes it perhaps a little more clear, and extend the functionality:
    dira[noparse][[/noparse]9..6] := %1111
    if ina[noparse][[/noparse]16] == 1
      outa[noparse][[/noparse]9..6] := %1111
    elseif ina[noparse][[/noparse]17] == 1
      outa[noparse][[/noparse]9..6] := %1010
    elseif ina[noparse][[/noparse]18] == 1
      outa[noparse][[/noparse]9..6] := %0011
    else
      outa[noparse][[/noparse]9..6] := %0000
    
    



    Andy
  • mikedivmikediv Posts: 825
    edited 2009-11-21 00:46
    Thanks guys , this was a little ahead of my programing skills but while I Was doing the I/O lab I was surprised it didn't explain how to control multiple outputs with one input the code you guys shared is a very good example for me thanks again
Sign In or Register to comment.