Shop OBEX P1 Docs P2 Docs Learn Events
5 LED Blink Challenge — Parallax Forums

5 LED Blink Challenge

ercoerco Posts: 20,254
edited 2015-06-25 20:44 in BASIC Stamp
It's on like a prawn that yawns at dawn. Who can write the smallest BS2 program to blink 5 LEDs independently at different (non-multiple and readily variable) rates?

Code, video & memory map count (eg: EEPROM 27% full) please.

Winner gets a free Quadrover, is that OK by you, Ken & Matt?

Comments

  • ercoerco Posts: 20,254
    edited 2015-06-24 20:15
    EEPROM 4% full. Video to follow.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
     DO
     W10=W10+1
     PAUSE 50
     IF W10/5*5=W10 THEN TOGGLE 0  ' value 5 is timing constant
     IF W10/9*9=W10 THEN TOGGLE 1
     IF W10/17*17=W10 THEN TOGGLE 2
     IF W10/29*29=W10 THEN TOGGLE 3
     IF W10/41*41=W10 THEN TOGGLE 4
     LOOP
    
    
  • ercoerco Posts: 20,254
    edited 2015-06-24 20:41
    A short-lived challenge.
  • Beau SchwabeBeau Schwabe Posts: 6,547
    edited 2015-06-24 21:36
    EEPROM 3% full. Video to follow.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
     DO
     W10=W10+1
     PAUSE 50
     IF W10 //5  =0 THEN TOGGLE 0  ' value 5 is timing constant
     IF W10 //9  =0 THEN TOGGLE 1
     IF W10 //17 =0 THEN TOGGLE 2
     IF W10 //29 =0 THEN TOGGLE 3
     IF W10 //41 =0 THEN TOGGLE 4
     LOOP
    

    Video Link:
    https://www.youtube.com/watch?v=wJ4jVkU86EU&feature=youtu.be
  • SapphireSapphire Posts: 496
    edited 2015-06-24 21:57
    EEPROM 2% Full.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    x VAR Word
    y VAR Word
    z VAR Word
    
    DO
      z = z + 1
      PAUSE 50
      FOR x = 0 TO 4
        LOOKUP x,[5,9,17,29,41],y
        IF z//y = 0 THEN TOGGLE x
      NEXT
    LOOP
    
  • Beau SchwabeBeau Schwabe Posts: 6,547
    edited 2015-06-24 23:37
    Still at 2% but this shaves off a few more bytes....
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    x VAR Nib
    y VAR Byte
    z VAR Word
    
    DO
      z = z + 1
      x = z // 5
      READ x,y
      IF (z/5)//y = 0 THEN TOGGLE x
    LOOP
    
    DATA 5,9,17,29,41
    
  • ercoerco Posts: 20,254
    edited 2015-06-25 07:32
    You guys are good! I'll consider myself clobbered. We'll need higher resolution than percent EEPROM full to gauge the compactness of your program's genius!
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2015-06-25 13:50
    Here's one not the shortest, but a different way to skin the stamp. Five NCO accumulators. Hard to tell the size with the MacBS2 memory map, 30 bytes I think, but lots of ram.
    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
      v VAR WORD
      w VAR WORD
      x VAR WORD
      y VAR WORD
      z VAR WORD
      
    DIRL=$FF 
    DO
      v = v+5
      w = w+7
      x = x+11
      y = y+13
      z = z+17
      OUT2 = v.BIT10
      OUT3 = w.BIT10
      OUT4 = x.BIT10
      OUT5 = y.BIT10
      OUT6 = z.BIT10
    

    Here is one that is very short, looks like 19 bytes without the Pause, or, 21 bytes with Pause to slow down the loop for LEDs.
    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    add CON 19
    mult CON 129
    DIRL=$ff
    DO
      OUTL = OUTL*mult + add
      PAUSE 128
    LOOP
    
    Okay, it barely squeaks by in terms of the challenge <-- blink 5 LEDs independently at different (non-multiple and readily variable) rates-->. It is basically a random number generator with the LEDs flashing erratically. Even so, the average rates and range of rates of the LEDs are different, and readily variable in a maddening sort of way if you play with the mult and add parameters. Average rates ratio for the parameters shown:
    353 : 163 : 224 : 447 : 288
  • ercoerco Posts: 20,254
    edited 2015-06-25 14:37
    Ah so, it pleases me to see the Master enter the fray. Thanks Tracy for two beautiful examples of outside the box thinking. This silly little challenge is bearing unexpected fruit. Namely, showing a variety of neat coding tricks by some smart guys who have crunched a fair amount of assembly and know how to do the most with the least.

    Quadrovers for all, I say. Matt, please see to it!
  • Beau SchwabeBeau Schwabe Posts: 6,547
    edited 2015-06-25 18:54
    Eric, I'll settle for some good conversation and a few drinks over dinner next time I'm out your direction. My luck, I'd drive the Quadrover into the creek. smirk
  • ercoerco Posts: 20,254
    edited 2015-06-25 20:44
    Sold! I'd buy that for a dollar!
Sign In or Register to comment.