November 23, 2024, 03:29:06 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Bi Color LEDs and the prop1

Started by enducer, October 26, 2009, 04:39:51 PM

Previous topic - Next topic

enducer

I have some Bi-colored LEDs in a prop, green/red

I was hoping to use both colors and make them flicker, but after installation I've realized that the common point of these is the anode, the negative. The prop 1's supply a common positive and switches the negative.

Is there a way around this ? Would my problem be solved using the header PINs?

If so what would the connections and programming be like?

SYMBOL   LEDGREEN = PIN5
SYMBOL   LEDRED = PIN4 

Thanks !





JonnyMac

October 26, 2009, 06:15:42 PM #1 Last Edit: October 26, 2009, 06:18:16 PM by JonnyMac
Assuming you have common cathode (cathode is the negative side of an LED), you can connect like this:



The reason for the smaller resistor on the green is that red LEDs tend to be brighter.  Note that this circuit is intended for the Prop-1 which already has 220-ohm resistors on each pin.

"Flicker" isn't a very specific request, so I whipped up this demo that will flicker the outputs for about 5 seconds after a trigger input.

' =========================================================================
'
'   File...... Bi-Color.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 26 OCT 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P6.W and P6.R


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  LedGreen        = 5
SYMBOL  LedRed          = 4


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  leds            = B2
SYMBOL  last            = B3
SYMBOL  delay           = B4

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


' -----[ Initialization ]--------------------------------------------------

Reset:
 PINS = %00000000                              ' clear all
 DIRS = %00110000                              ' set output pins


' -----[ Program Code ]----------------------------------------------------

Main:
 timer = 0                                     ' reset timer

Check_Trigger:
 PAUSE 5                                       ' loop pad
 timer = timer + 5 * Trigger                   ' update timer
 IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

 timer = 0

Flicker:
 RANDOM lottery
 leds = lottery & %00110000
 IF leds = last THEN Flicker
   last = leds
 PINS = PINS &/ %00110000 | leds               ' update leds, protect others
 RANDOM lottery
 delay = lottery // 51 + 25                    ' 25 to 75ms
 PAUSE delay
 timer = timer + delay
 IF timer < 5000 THEN Flicker
   GOTO Reset


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office