Shop OBEX P1 Docs P2 Docs Learn Events
Can't Get the Lights On — Parallax Forums

Can't Get the Lights On

XetarXetar Posts: 10
edited 2010-10-28 18:15 in Propeller 1
I'm trying to get 3 LED's to represet the first 3 bits in a variable (BYTE lclState). The variable will contain a number from 0 to 5. So far nothing I've tried has worked. I've either got all lights on or nothing.

This code here turns all the lights on no matter what.

outa[12] := (lclState and %001) <> 0
outa[13] := (lclState and %010) <> 0
outa[14] := (lclState and %100) <> 0

Comments

  • ratronicratronic Posts: 1,451
    edited 2010-10-28 14:49
    Xetar, you could try something like this - outa[14..12] := lclState & 7
  • XetarXetar Posts: 10
    edited 2010-10-28 14:57
    It looks like this did the trick:

    outa[12..14] := lclState
  • ratronicratronic Posts: 1,451
    edited 2010-10-28 15:09
    The '& 7' on the end of it was to isolate the first three bits of lclState.
  • localrogerlocalroger Posts: 3,452
    edited 2010-10-28 16:44
    ratronic, you don't need the &7 because the outa[14..12] does the masking function.
  • ratronicratronic Posts: 1,451
    edited 2010-10-28 17:16
    Thanks for pointing that out localroger!
  • mparkmpark Posts: 1,305
    edited 2010-10-28 18:15
    Xetar wrote: »
    I'm trying to get 3 LED's to represet the first 3 bits in a variable (BYTE lclState). The variable will contain a number from 0 to 5. So far nothing I've tried has worked. I've either got all lights on or nothing.

    This code here turns all the lights on no matter what.

    outa[12] := (lclState and %001) <> 0
    outa[13] := (lclState and %010) <> 0
    outa[14] := (lclState and %100) <> 0

    Try replacing "and" with "&". You want the bitwise and operator.
Sign In or Register to comment.