Picaxe RGB controller.

eclectic

Moderator
Draft 1

A Picaxe RGB self contained controller.

The original ”Pulsout” ideas, proposed by Hippy and Tom2000,
come from these threads:

http://www.picaxeforum.co.uk/showthread.php?t=8991
http://www.picaxeforum.co.uk/showthread.php?t=9657&page=2

My apologies if I've missed any others.

A cheap (£2 GB) Picaxe can control
A c/c RGB LED / Three separate LED's /High power or banks of LED's.
See basic circuit diagram.

Resistor values must be found by experiment or calculation.
For safety, start with 1000 ohms, then reduce the value, while measuring LED current.

Valid output pins.
08M 0,1,2,4
18X / 20M / 28X1 / 40X1 0...8

Prog 1. Cycles through values. Could be “prettied” to the nth degree.
Code:
symbol rTime = b0
symbol gTime = b1
symbol btime = b2
symbol xtime = w2
symbol R_LED = 0
symbol G_LED = 1
symbol B_LED = 2
symbol dummy = 3  ; 4 if 08M ***

setfreq m8
 main:
 for rTime = 10 to 255 step 10
 for gTime = 0 to 255 step 10
 for bTime = 0 to 255 'step 5
  
 xTime = 766 - rTime - gTime - bTime
 PulsOut R_LED, rTime
 PulsOut G_LED, gTime
 PulsOut B_LED, bTime
 PulsOut DUMMY, xTime
 next
 next
 next
For an eight output Picaxe, adding the lines

Code:
 PulsOut 4, bTime
 PulsOut 5, gTime
 PulsOut 6, rTime
 PulsOut 7, xTime
will control two sets of RGB lights, showing two different patterns.
With suitable maths/coding it should be possible to create complementary colours
and other interesting effects.


Program 2. A wonderful Penicillium green.
Code:
symbol rTime = b0
symbol gTime = b1
symbol btime = b2
symbol xtime = w2
symbol R_LED =0
symbol G_LED =1
symbol B_LED =2
symbol dummy = 3

setfreq m8
 do
  
  rTime = 60
  gTime = 250
  bTime = 80 
  
 xTime = 766 - rTime - gTime - bTime
 PulsOut R_LED, rTime
 PulsOut G_LED, gTime
 PulsOut B_LED, bTime
 PulsOut DUMMY, xTime
 
loop
A “Master” Picaxe, using Serout, can send rTime, gTime and bTime values,
allowing the “slave”to function as a “standalone” RGB controller.
 

Attachments

Last edited:

Jsmirnio

New Member
LED Pushbutton Dimmer

Always hard to find this simple code for a push-button control LED dimmer using PWM. This one uses a PicAxe 08M.

Link to breadboard setup - http://rad.usuhs.edu/medpix/medpix.html?mode=quiz&imid=49240&quiz=&th=&table=card&showall=#pic

Photograph - http://rad.usuhs.edu/medpix/raw_image.html?mode=quiz&imid=49237&quiz=&th=&table=card&showall=#pic

' < ================================ >
' PushButton_PWM_Control-Rev-3.bas
'
' Momentary pushbuttons on Physical Pin3 and Pin4
' Ouput to Physical PIN 5 (Pin2)
' Status LED on Physical PIN 7 (Pin0)
'
' Output starts at medium.
'
' If one pushbutton is depressed the Duty is decreased, lowering power.
' If one pushbutton is depressed the Duty is increased, increasing power
' If both buttons are depressed, the output is zero.
'
' Status LED flashes each time through the loop.
' Input pins held low by 10K-22K pull-down resistor
' LED has 330 current limit resistor

'
' Modified by JGS May '09, Silver Spring, MD
' Original PWM by Peter H Anderson, Baltimore, Mar, '04



' Assign Input/Output pins
symbol modeUp_btn = pin3 'INPUT from physical PIN 4;
symbol modeDn_btn = pin4 'INPUT from physical PIN 3;
symbol led_pin = 2 'OUTPUT to physical PIN 5;

symbol Duty = W0

Duty = 400 'Start with medium duty (400/1024)
PWMOut 2, 249, Duty 'OUTPUT to physical PIN 5 - Period 249, @ Duty/1024

' PWMOut runs continuously until changed by another PWMOut


TOP:

GoSub Flash ' flash Status LED on Out0

'SerTxD (#Duty, 13, 10) ' used for debugging student programs

If modeDn_btn = 1 and modeUp_btn = 0 Then Less ' if Less depressed
If modeDn_btn = 0 and modeUp_btn = 1 Then More ' if More depressed
If modeUp_btn = 1 and modeDn_btn = 1 Then Dark ' if both pushbuttons depressed
' no change if neither depressed.

GoTo TOP ' lather - rinse - repeat


Less:
If Duty < 40 Then TOP ' minimum Duty floor
Duty = Duty - 30 ' otherwise decrease duty
PWMOut 2, 249, Duty
Pause 100

GoTo TOP

More:
If Duty > 984 Then TOP ' maximum Duty ceiling
Duty = Duty + 30 ' otherwise increase duty
PWMOut 2, 249, Duty
Pause 100

GoTo TOP

Dark:
PWMOut 2, 0, Duty ' zero the period (FULL STOP/DARK)

GoTo TOP

Flash: ' Flash Button Status LED
High 0
Pause 100
Low 0
Pause 100
Return
 
Top