Shop OBEX P1 Docs P2 Docs Learn Events
little project ... - Page 4 — Parallax Forums

little project ...

1246789

Comments

  • elecnoobelecnoob Posts: 123
    edited 2007-08-23 15:54
    hey ..
    i' m just tring to do something very easy but even that won't work .. can you please help me out ..
    [noparse][[/noparse]code]
    pub main
    if ina
    dira[noparse][[/noparse]8] ~~
    repeat
    !outa[noparse][[/noparse]8]
    waitcnt(3_000_000 + cnt )
    [noparse][[/noparse]/]

    so ina 1 is a switch and outa 8 is a led .. what i'm tring to do is just clcik on the swith and the led must start pinking
    but it won't do that .. what do i do wrong ?
    please help .
  • rjo_rjo_ Posts: 1,825
    edited 2007-08-23 16:12
    ? do you mean:

    repeat
    outa[noparse][[/noparse]8]:=0
    while ina[noparse][[/noparse]pinnummer]==1
    repeat
    !outa[noparse][[/noparse]8]
    waitcnt(3_000_000 +cnt)
  • elecnoobelecnoob Posts: 123
    edited 2007-08-23 16:18
    rjo_ do you speak dutch ?

    he gives a error on the while.. and i don't get it he ecpects an instruction or variable .. insted of the while
  • Franz AchatzFranz Achatz Posts: 140
    edited 2007-08-23 17:25
    ik praat ook een beetje nederlands.
    Mischien werkt deze bij je:

    PUB Toggle
    dira[noparse][[/noparse]outpin]~~
    dira[noparse][[/noparse]inpin] := 1
    repeat
    outa[noparse][[/noparse]outpin]:=0
    repeat while ina[noparse][[/noparse]inpin] == 1
    !outa[noparse][[/noparse]outpin]
    waitcnt(3_000_000 +cnt)

    groetjes
    Franz
  • elecnoobelecnoob Posts: 123
    edited 2007-08-23 17:26
    wat is je moedertaal ?
    bij mij nederlands .. en het is gelukt met het vorige .. tog bedankt ( srry )
    maar hij wilt het niet doen .. ben nu mijn hardware aan het aanpassen . zoals het in de editor staat [noparse];)[/noparse]
    grtz
  • Franz AchatzFranz Achatz Posts: 140
    edited 2007-08-23 17:33
    elecnoob said...
    wat is je moedertaal ?
    bij mij nederlands ..
    bij mij duits, om precies te zijn is het bayerisch smile.gif

    groetjes
    Franz
  • elecnoobelecnoob Posts: 123
    edited 2007-08-23 17:34
    ken ik niet tongue.gif (mag ik in het nederlands verder gaan of liever engels?)

    can it be that the switch on the inputport doesn't work that good because it's not the same construction
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-23 17:47
    Well,
    (1) Could you both please post your code as code! This should not be a matter of the mother language...
    (2) I think some problems are caused by wrind indention
    (3) And if you don't include the IF inside the REPEAT-loop, this will stay a tricky program smile.gif
  • rjo_rjo_ Posts: 1,825
    edited 2007-08-23 18:29
    grtz,

    I speak Dutch... but only in English[noparse]:)[/noparse]
    The indentation gets messed up in the posts. Try taking a snapshot of your code and attaching it.

    Rich
  • elecnoobelecnoob Posts: 123
    edited 2007-08-23 20:18
    pub memory
    
     
        w := 1
        z := 0      
      repeat 17
        
          repeat w    
           X := startpin + ||i?//8           ' set X to a random number from 0 to 8 , starpin for the output. if the random number =0 it will start at a defined pinnumber
           dira[noparse][[/noparse]X] ~~                                      
           !outa[noparse][[/noparse]X]                          ' put the led on
            waitcnt(delay + cnt )
                                              ' waiting time to hold the led lighted
           if outa[noparse][[/noparse]x]                    ' put pin X on 1 ( light op a led)
             outputreg [noparse][[/noparse]z] === x              ' to save what outpin has gone to 1
             z === z + 1                      ' z must add by 1 so the next won't overwrite the array
             outa[noparse][[/noparse]x]===0
             
          repeat  
            if ina
            x := 1
             repeat 
             until w===x 
              if ina[noparse][[/noparse]0] === 1                   ' next lines are to see what switsh is pressed
               inputreg [noparse][[/noparse]j] === 8
               j := j + 1
               x:=x+1
              elseif ina == 1
               inputreg[noparse][[/noparse]j] === 9
               j := j + 1
               x:=x+1
              elseif ina === 1
               inputreg[noparse][[/noparse]j] === 10
               j := j + 1
               x:=x+1
              elseif ina === 1
               inputreg[noparse][[/noparse]j] === 11
               j := j + 1
               x:=x+1
              elseif ina === 1
               inputreg[noparse][[/noparse]j] === 12
               j := j + 1
               x:=x+1
              elseif ina === 1
               inputreg[noparse][[/noparse]j] === 13
               j := j + 1
               x:=x+1
              elseif ina[noparse][[/noparse]6] === 1
               inputreg[noparse][[/noparse]j] === 14
               j := j + 1
               x:=x+1
              elseif ina[noparse][[/noparse]7] === 1
               inputreg[noparse][[/noparse]j] ===15
               j := j + 1
               x:=x+1
             
              quit
              
          v === 0
          repeat w
            if outputreg[noparse][[/noparse]v] == inputreg[noparse][[/noparse]v]     ' compare the values in the 2 arrays
             v := v + 1 
           w:=w+1
    
    
    



    i also have an other question .. can i have a debug form to see what the prop.chip is doing from code?

    grtz
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-23 21:01
    Where for heaven's sake did you get === from????
    Well it has a meaning (though I doubt a useful one) but please forget this if you ever can!

    To assign values, use ":="
    The check for equaity, use "=="

    Please change your program and post it again... PLEASE!
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-23 21:06
    @elecnoob: Why do I post at all? My impression is, you are a highly intelligent person;
    I doubt someone with an IQ lower that 140 can think of all the nonsense you are doing.
    I in fact do enjoy it! MENSA? An alien?
  • elecnoobelecnoob Posts: 123
    edited 2007-08-23 21:06
    the program doesn't accept a "==" it only accepts the tripple 1 ..
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-23 22:50
    which program? The forum post dialog?
  • rjo_rjo_ Posts: 1,825
    edited 2007-08-23 23:25
    I had to look this up[noparse]:)[/noparse]

    === is legal. Page 438.

    X===Y

    sets X to true (-1) if x=y, it sets X to (0) if not.
  • MarkSMarkS Posts: 342
    edited 2007-08-23 23:50
    rjo_ said...
    I had to look this up[noparse]:)[/noparse]

    === is legal. Page 438.

    X===Y

    sets X to true (-1) if x=y, it sets X to (0) if not.

    So, its essentially a shorted version of X == Y ? -1 : 0 (in C)? If so, COOL!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-24 00:03
    I believe = = = is the usual case of the overloaded assignment operator like += or &=.
    X === Y is identical to X := X == Y which sets X true (-1) if X == Y and false (0) otherwise, just like rjo_ found.
  • rjo_rjo_ Posts: 1,825
    edited 2007-08-24 00:25
    But didn't exactly state correctly... thanks Mike[noparse]:)[/noparse]
  • elecnoobelecnoob Posts: 123
    edited 2007-08-24 13:05
    so the === isn't equal ? ...
    because if i said == the program says to me that the varriable needs an operator ..
    so i just used the === because my small datasheet says that == is the same as ===
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-24 13:19
    For the "ina[noparse][[/noparse] x ] == 1" and similar places, you need the equal comparison operator "==".

    For the "inputreg[noparse][[/noparse] j ] := y" and similar places, you need the assignment operator ":=".
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 13:44
    rjo_ said...
    I had to look this up
    This is not good, rjo_ : It means that you stil have no "feeling" for SPIN smile.gif
    === is a most systematic and obvious construction! (as =>= and =<= e.g.)
  • elecnoobelecnoob Posts: 123
    edited 2007-08-24 14:55
    outa[noparse][[/noparse]x] == 0

    but here he gaives the error ...
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 15:05
    One by one smile.gif
    I asked you about 24 hours ago to make the changes according to my suggestions,
    and then post your code again, PLEASE.

    The reason is, that after you do this, the about 4 grave logical errors in your program,
    will be more obviuous to others - when you get rid of these idiotic ===
    Thank you
  • elecnoobelecnoob Posts: 123
    edited 2007-08-24 15:09
    ok i will post my code again .. but i made allot of changes ..
    pub memory
    
    dira[noparse][[/noparse]0] := 0
    dira := 0
    dira := 0
    dira := 0
    dira := 0
    dira := 0
    dira[noparse][[/noparse]6] := 0
    dira[noparse][[/noparse]7] := 0
    dira[noparse][[/noparse]8] := 1
    dira[noparse][[/noparse]9] := 1
    dira[noparse][[/noparse]10] := 1
    dira[noparse][[/noparse]11] := 1
    dira[noparse][[/noparse]12] := 1
    dira[noparse][[/noparse]13] := 1
    dira[noparse][[/noparse]14] := 1
    dira[noparse][[/noparse]15] := 1
    
     
        w := 1
         
      repeat 17
          x := 0
          z := 0
          j := 0 
          repeat 17
            outputreg [noparse][[/noparse]x] == 0
            inputreg [noparse][[/noparse]x] == 0
            x := x + 1
          repeat w    
           X := startpin + ||i?//8          ' set X to a random number from 0 to 8 , starpin for the output. if the random number =0 it will start at a defined pinnumber
           dira[noparse][[/noparse]X] ~~                                      
           !outa[noparse][[/noparse]X]                          ' put the led on
            waitcnt(delay + cnt )
                                              ' waiting time to hold the led lighted
           outputreg [noparse][[/noparse]z] == x
           'if outa[noparse][[/noparse]x]                    ' put pin X on 1 ( light op a led)
           '  outputreg [noparse][[/noparse]z] == x              ' to save what outpin has gone to 1
           z := z + 1                      ' z must add by 1 so the next won't overwrite the array
           outa[noparse][[/noparse]x] == 0
           waitcnt(delay2 + cnt ) 
             
          repeat w                          ' to see what switch is pressed
            repeat 
               if ina [noparse][[/noparse]0..7]
                 outa[noparse][[/noparse]8] := ina[noparse][[/noparse] 0 ]
                 outa[noparse][[/noparse]9] := ina[noparse][[/noparse] 1 ]
                 outa[noparse][[/noparse]10] := ina[noparse][[/noparse] 2 ]
                 outa[noparse][[/noparse]11] := ina[noparse][[/noparse] 3 ]
                 outa[noparse][[/noparse]12] := ina[noparse][[/noparse] 4 ]
                 outa[noparse][[/noparse]13] := ina[noparse][[/noparse] 5 ]
                 outa[noparse][[/noparse]14] := ina[noparse][[/noparse] 6 ]
                 outa[noparse][[/noparse]15] := ina[noparse][[/noparse] 7 ] 
                 'if ina[noparse][[/noparse]0] 
                 '  inputreg [noparse][[/noparse]j] := 8
                 '  j := j + 1
                   
                 'elseif ina 
                 '  inputreg[noparse][[/noparse]j]:= 9
                 '  j := j + 1
                 
                 'elseif ina   
                 '  inputreg[noparse][[/noparse]j] := 10
                 '  j := j + 1
                 
                 'elseif ina  
                 '  inputreg[noparse][[/noparse]j] := 11
                 '  j := j + 1
                 
                 'elseif ina   
                 '  inputreg[noparse][[/noparse]j] := 12
                 '  j := j + 1
                 
                 'elseif ina   
                 '   inputreg[noparse][[/noparse]j] := 13
                 '   j := j + 1
                 
                 'elseif ina[noparse][[/noparse]6]   
                 '  inputreg[noparse][[/noparse]j] := 14
                 '  j := j + 1
                 
                 'elseif ina[noparse][[/noparse]7]   
                 '  inputreg[noparse][[/noparse]j] :=15
                 '  j := j + 1
                  
                 
                waitcnt(delay2 + cnt )
                outa[noparse][[/noparse]8] := 0
                outa[noparse][[/noparse]9] := 0
                outa[noparse][[/noparse]10] := 0
                outa[noparse][[/noparse]11] := 0
                outa[noparse][[/noparse]12] := 0
                outa[noparse][[/noparse]13] := 0 
                outa[noparse][[/noparse]14] := 0
                outa[noparse][[/noparse]15] := 0
                quit       
    
                
                
             
              
              
      '   v := 0
      '    repeat w
      '      if outputreg[noparse][[/noparse]v] == inputreg[noparse][[/noparse]v]     ' compare the values in the 2 arrays
      '       v := v + 1                      ' next array   
      '  w:=w+1
    
    
    



    all the ' are because i'm just testing the program step by step ..
    right now ..
    the leds turn on and of in a random sequence and wait till as mutch as buttons are pushed as there wereled lighted on
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 15:20
    Can you explain me, when do you use "==" and when ":=" ?
  • elecnoobelecnoob Posts: 123
    edited 2007-08-24 15:25
    == to place something in an arry
    and := for all the others
    ( but like i said .. the lines behind the ' i need to change before i can use it .. they are from a edition before this 1 .. but that didn't work so now i'm trying
    to rewrite it .. in steps ..
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 15:26
    Two tips: There are some nice features in SPIN. One ofthem: For I/O registers, and ONLY for I/O registers ,
    you can write:
        outa[noparse][[/noparse] 8..15 ] := 0
    and
       outa[noparse][[/noparse] 8..15 ] := ina[noparse][[/noparse] 0..7 ]
    
    rather than:
    
                 outa[noparse][[/noparse]8] := ina[noparse][[/noparse] 0 ]
                 outa[noparse][[/noparse]9] := ina[noparse][[/noparse] 1 ]
                 outa[noparse][[/noparse]10] := ina[noparse][[/noparse] 2 ]
                 outa[noparse][[/noparse]11] := ina[noparse][[/noparse] 3 ]
                 outa[noparse][[/noparse]12] := ina[noparse][[/noparse] 4 ]
                 outa[noparse][[/noparse]13] := ina[noparse][[/noparse] 5 ]
                 outa[noparse][[/noparse]14] := ina[noparse][[/noparse] 6 ]
                 outa[noparse][[/noparse]15] := ina[noparse][[/noparse] 7 ] 
     
               outa[noparse][[/noparse]8] := 0
                outa[noparse][[/noparse]9] := 0
                outa[noparse][[/noparse]10] := 0
                outa[noparse][[/noparse]11] := 0
                outa[noparse][[/noparse]12] := 0
                outa[noparse][[/noparse]13] := 0 
                outa[noparse][[/noparse]14] := 0
                outa[noparse][[/noparse]15] := 0
    


    This will improve readeability!

    Post Edited (deSilva) : 8/24/2007 3:31:55 PM GMT
  • elecnoobelecnoob Posts: 123
    edited 2007-08-24 15:27
    ok tnx ( i think i used it 1 in a if .. )
    can i also do this with the dira?
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 15:28
    elecnoob said...
    == to place something in an array
    There is no difference where you place things, it's ALWAYS ":="

    "==" is a check for equality, to be used within IF, WHILE e.t.c
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 15:31
    elecnoob said...
    can i also do this with the dira?
    I said: For all I/O registers and ONLY for I/O registers...
Sign In or Register to comment.