Shop OBEX P1 Docs P2 Docs Learn Events
Why do all 3 leds blink at same rate ? — Parallax Forums

Why do all 3 leds blink at same rate ?

tj4sheetj4shee Posts: 25
edited 2012-08-09 18:20 in Propeller 1
Not sure why my previous post never made it to the forum..... hopefully this one will...

I am brand new to the propeller.... like the idea of 8 'cogs'.....

How come the following code has the result of all 3 leds blinking at the same time..... verses each of them 'twinkling' at their own rate as I thought the program specifies....
CON

  _clkmode = xtal1 + pll16x         'Establish speed
  _xinfreq = 5_000_000              '80Mhz


OBJ


  led: "E555_LEDEngine.spin"        'Include LED methods object


VAR


  byte Counter                      'Establish Counter Variable
  long stack[90]                    'Establish working space


PUB Main


  cognew(Twinkle(16,clkfreq/150), @stack[0])   'start Twinkle cog 1
  cognew(Twinkle(17,clkfreq/200), @stack[30])  'start Twinkle cog 2
  cognew(Twinkle(18,clkfreq/250), @stack[60])  'start Twinkle cog 3


PRI Twinkle(PIN,RATE)                  'Method declaration


  repeat                               'Initiate a master loop


    repeat Counter from 0 to 100       'Repeat loop Counter
      led.LEDBrightness(Counter, PIN)  'Adjust LED brightness
      waitcnt(RATE + cnt)              'Wait a moment


    repeat Counter from 100 to 0       'Repeat loop Counter
      led.LEDBrightness(Counter,PIN)   'Adjust LED brightness
      waitcnt(RATE + cnt)              'Wait a moment

FYI... I originally had the Twinkle method as PUB... but get the same results

I am an accomplished MCU developer.... but not on Propeller... so thanks for being patient.

TJ

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-08-09 15:39
    The variable "Counter" needs to be a local variable.
    PRI Twinkle(PIN,RATE) | Counter
    
    
    Delete Counter from the VAR section.

    I'm not sure if that will solve the problem. It just jumps out at me.
  • kuronekokuroneko Posts: 3,623
    edited 2012-08-09 16:04
    This must be the third time this pops up. Just saying ...
  • tj4sheetj4shee Posts: 25
    edited 2012-08-09 18:02
    Thanks Duane ! That was it......

    Duane Degn wrote: »
    The variable "Counter" needs to be a local variable.
    PRI Twinkle(PIN,RATE) | Counter
    
    
    Delete Counter from the VAR section.

    I'm not sure if that will solve the problem. It just jumps out at me.
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-08-09 18:20
    The code in the multi-cog example is wrong. It's exactly how tj4shee keyed it in and it doesn't work. I thought we had informed Parallax on that thread and got an acknowledgement about this the last time (or first time) it cropped up.
Sign In or Register to comment.