Shop OBEX P1 Docs P2 Docs Learn Events
When would you use INA = 1 Nibble Names instead of IN0 Bit Name Please — Parallax Forums

When would you use INA = 1 Nibble Names instead of IN0 Bit Name Please

sam_sam_samsam_sam_sam Posts: 2,286
edited 2009-05-23 01:22 in Learn with BlocklyProp
When would you use·OUTA = 1· Nibble Names·· instead of·OUT1·· Bit Name···· Please Give an Example
what different if you used this··HIGH 1·or LOW 1···instead of the···OUT1··or OUTA = 1
I have read·PBasic Syntax·a few time on this ·But·I not clear on when to use what

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 5/21/2009 3:49:02 AM GMT

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-05-21 04:56
    You can use it to set four outputs at once, not just a single one. Simple convenience is all.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-05-21 14:56
    Sam,

    I was a bit confused as your subject referred to the INA statement, but your message refers to OUTA. In any event, OUTA can set 4 outputs at a time rather than just one set by a single HIGH/LOW statement, however, unless the DIRA register was set to output, the value set to OUTA will never be seen on the pins, since OUTA does not automatically make the pins an output as the HIGH/LOW commands do.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-05-21 15:18
    And if you are interested in when to use inA versus individual bits, say you are monitoring a pinewood derby and you want to detect without bias which car crossed the finish line first. If you do,
    DO
      winners = INA
      IF winners>0 THEN finish
    LOOP
    


    that will detect a tie better than doing,
    DO
      laneA=in0
      laneB=in1
      laneC=in2
      laneD=in3
      IF lane1 | lane2 | lane3 | lane4 THEN finish
    LOOP
    


    because in the former case the test of all the inputs happens at essentially the same time, whereas in the second case the tests of the individual bits are done about 0.15 milliseconds apart. Sometimes that matters. The first example also runs through the DO:LOOP much faster and has better time resolution. Any time you want to input or output multiple pins and go through a sequence FAST, the option of INS and OUTS will win over dealing with individual pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-05-21 15:34
    Hi Sam, I like the DIR , IN and OUT instructions. As mentioned they allow for control of as many as 16 I/O pins simultaneously.

    A typical application might be the control of a stepper motor, if you search I am sure you will find an example.

    Chris brought up a good point that is not immediately obvious·"unless the DIRA register was set to output, the value set to OUTA will never be seen on the pins" , the order in which you write the instructions in code has an effect on the way OUTA operates. What I am saying is that DIR does not neccessarily have to come before the OUT instruction , DIR can be used to "switch" a preset value of OUT.

    Example

    OUTA=%1111 'here P0,P1,P2 and P3 have been set high but until we issue the DIR instruction the result will not be seen at the output

    DIRA=%1111 ' here OUTA has been set to output in effect switching P0,P1,P2 and P3 to logic 1

    DIRA=%0000 ' here OUTA has been set to input in effect switching P0,P1,P2 and P3 to logic 0

    That is not the be all and end all of DIR and OUT but just an aspect I find interesting and useful at times

    Jeff T.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-21 21:41
    Unsoundcode ,Tracy Allen


    ·Thank You for explaining this to me and your examples this has help me a lot

    Chris

    Thank You for your reply and explanation

    I was a bit confused as your subject referred to the INA statement, but your message refers to OUTA. In any event,

    I did not mean to confuse you or anyone· but the subject line was not long enough to put all of what I want to ask about



    SRLM

    Thank you for your·very simple explanation


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • ZootZoot Posts: 2,227
    edited 2009-05-22 21:54
    Here's a code example that would be much longer (and actually not as useful) w/o INA, DIRA and the like:

    
    ' hookup 8 leds to pins 0-7
    
    OUTL = %00000001 ' when outputs, first led on
    DIRL = %11111111 ' make 'em outputs
    
    
    DO
      PAUSE 250
      IF OUTL = %10000000 THEN
         OUTL = %00000001
      ELSE
         OUTL = OUTL << 1
      ENDIF
    LOOP
    
    END
    
    



    Also see some of the line-following code examples for the Boe-bot which grab all the line sensors at once using IN<x>, etc.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-23 00:13
    Zoot

    Thank you for your reply

    I will try this when I have some time



    '·hookup·8·leds·to·pins·0-7

    OUTL·=·%00000001·'·when·outputs,·first·led·on
    DIRL·=·%11111111·'·make·'em·outputs


    DO
    ··PAUSE·250
    ··IF·OUTL·=·%10000000·THEN
    ·····OUTL·=·%00000001
    ··ELSE
    ·····OUTL·=·OUTL·<<·1
    ··ENDIF
    LOOP

    END




    Also see some of the line-following code examples for the Boe-bot which grab all the line sensors at once using IN<x>, etc.

    Could you post the link to this with the pages #

    ·I would like to read up on this IN<x> and line-following code examples for the Boe-bot

    Thanks for·sharing this··· smile.gif






    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • ZootZoot Posts: 2,227
    edited 2009-05-23 01:01
    http://forums.parallax.com/showthread.php?p=593855

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-23 01:22
    Zoot

    Thanks for the Link

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.