Shop OBEX P1 Docs P2 Docs Learn Events
Running LCD display + LEDs at the same time — Parallax Forums

Running LCD display + LEDs at the same time

RobertWRobertW Posts: 66
edited 2010-02-14 19:22 in Propeller 1
I believe this question could be in the area of Propeller cogs 101 but I am still having a little trouble getting what I am looking for.· As a 'learning exercise' I am trying to print 'Initializing' then a series of periods (.) after that for about·5 times.· At the same time I would like to blink some LEDs.· The pattern of the LEDs is not important at this point and flashing one after the other is fine.· Each works fine seperately but not combined.· I'm thinking that I need to start the next cog and run the LCD in 1 cog and the LEDs in another cog.· This is my current setup:

Main program
······ - LCD object
······ - LEDs object

The main program initializes the LCD and calls different methods as required.· The same with the LCD object.· Any suggestions on how to properly start·the LCD·in it's own cog?· I think I can figure out the LEDs.

Since I need to initialize the LCD, print the 'Initalizing' method, and then print different messages later in the program, how should I keep the LCD cog running?· If I understand cogs correctly, they will stop when they run out of code.· How do you prevent this while waiting to receive a message from the main object?· Would I need some sort of repeat loop?

Thank you.
-Robert W

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-02-14 06:08
    LCDs don't tend to need a separate cog (from your main program, that is) unless you need to employ some sort of buffering for the display. Start you LED object flashing (in its own cog) and then write to the display with your program. Now... if coordination between what you write and what's happening with the LEDs is required you'll need some sort of method in the LED object to allow that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • RobertWRobertW Posts: 66
    edited 2010-02-14 18:51
    Hi Jon,

    Thanks for the reply.· I probably did not explain what I was trying to do very well, but yes, your question is exactly what I am trying to do.· I would like to print something on the display and flash the LEDs at the same time.· It is my understanding that I can try to time the two with a repeat loop or start one of them in a new cog.· Is this correct?

    Thanks.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-02-14 19:22
    Well, if your process is A) print something, B) flash LEDs, C) repeat... then you don't need a separate cog, just create a flash method for your LED(s) that you can call when needed. For example, you might do something like this:

    pub flashled(pin, ontime, offtime, flashes) | ms001, t
    
      ms001 := clkfreq / 1_000                              ' ticks in 1ms
    
      dira[noparse][[/noparse]pin]~~                                           ' make pin an output
    
      t := cnt                                              ' sync with system timer
      repeat flashes
        outa[noparse][[/noparse]pin]~~                                         ' output on
        repeat ontime                                       ' hold for on-time
          waitcnt(t += ms001)
        outa[noparse][[/noparse]pin]~                                          ' output off
        repeat offtime                                      ' hold for off-time
          waitcnt(t += ms001)    
    
      dira[noparse][[/noparse]pin]~                                            ' disable pin
    



    This is a flexible routine, allowing you to specify the pin, on- and off-timing (in milliseconds, for duty cycle), and the number of flashes. If you call this like a regular method it will "block" the main program. You can launch it into its own cog if you choose, but you may want to add cogstop at the end.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
Sign In or Register to comment.