LED pattern selection

Coding and general discussion relating to the compiler

Moderators: Jerry Messina, David Barker

Post Reply
joshua17ss2
Posts: 2
Joined: Fri Apr 18, 2008 5:16 pm
Location: romulus

LED pattern selection

Post by joshua17ss2 » Fri Dec 28, 2012 4:13 pm

I am using a pic 18f2550 with a pair of ULN2803 buffers to drive 9- 3 watt UV LED's. I am stuck on the coding to actually run this thing, I am by no means a programmer much better at hardware. I have managed to set up a simple structure to define my outputs, and set up the sub routines for the patterns i want to define.
I have to problems with coding i can figure out, the first being how to loop each pattern until the button is pressed, which then moves on to the next pattern.
and how to tell the program to move from pattern to pattern with each button press.

Can I use a repeat command in each subroutine to loop the individual patterns until the button is pressed?

And im completely blank on how to tell the button to move from pattern to pattern ?

Any help would be appreciated.


CODE:
Device = 18F2550
Clock = 8
Config FOSC = INTOSCIO_EC


Include "utils.bas"

Dim Switch As PORTA.0
dim UVLED1 As PORTB.0
dim UVLED2 As PORTB.1
dim UVLED3 As PORTB.2
dim UVLED4 As PORTB.3
dim UVLED5 As PORTB.4
dim UVLED6 As PORTB.5
dim UVLED7 As PORTB.6
dim UVLED8 As PORTB.7
dim UVLED9 As PORTC.7

Sub Debounce()

DelayMS(10)

While Switch = 1
Wend

End Sub

Sub Pattern1()
PORTB = %10101010
UVLED9 = 1
DelayMS(1000)
PORTB = %01010101
UVLED9 = 0
DelayMS(1000)
PORTB = %10101010
UVLED9 = 1
DelayMS(1000)
PORTB = %01010101
UVLED9 = 0
DelayMS(1000)
End Sub

Sub Pattern2()
PORTB = %11111111
UVLED9 = 1
DelayMS(1000)
PORTB = %00000000
UVLED9 = 0
DelayMS(1000)
PORTB = %11111111
UVLED9 = 1
DelayMS(1000)
PORTB = %00000000
UVLED9 = 0
DelayMS(1000)
End Sub

Sub Pattern3()
PORTB = %10000000
DelayMS(500)
PORTB = %01000000
DelayMS(500)
PORTB = %00100000
DelayMS(500)
PORTB = %00010000
DelayMS(500)
PORTB = %00001000
DelayMS(500)
PORTB = %00000100
DelayMS(500)
PORTB = %00000010
DelayMS(500)
PORTB = %00000001
DelayMS(500)
PORTB = %00000000
DelayMS(500)
UVLED9 = 1
DelayMS(500)
UVLED9 = 0
DelayMS(500)
PORTB = %00000001
DelayMS(500)
PORTB = %00000010
DelayMS(500)
PORTB = %00000100
DelayMS(500)
PORTB = %00001000
DelayMS(500)
PORTB = %00010000
DelayMS(500)
PORTB = %00100000
DelayMS(500)
PORTB = %01000000
DelayMS(500)
PORTB = %10000000
DelayMS(500)
PORTB = %00000000

End Sub

Sub Pattern4()
PORTB = %10101010
UVLED9 = 1
DelayMS(1000)
PORTB = %01010101
UVLED9 = 0
DelayMS(1000)
PORTB = %10101010
UVLED9 = 1
DelayMS(1000)
PORTB = %01010101
UVLED9 = 0
DelayMS(1000)
End Sub

Sub Pattern5()
PORTB = %10101010
UVLED9 = 1
DelayMS(1000)
PORTB = %01010101
UVLED9 = 0
DelayMS(1000)
PORTB = %10101010
UVLED9 = 1
DelayMS(1000)
PORTB = %01010101
UVLED9 = 0
DelayMS(1000)
End Sub

Sub Pattern6()
PORTB = %10101010
UVLED9 = 1
DelayMS(1000)
PORTB = %01010101
UVLED9 = 0
DelayMS(1000)
PORTB = %10101010
UVLED9 = 1
DelayMS(1000)
PORTB = %01010101
UVLED9 = 0
DelayMS(1000)
End Sub

OSCCON = %01111111
SetAllDigital

Input(Switch)
TRISB = %00000000
PORTB = %00000000
Low(UVLED9)

While True
Repeat
Until Switch = 1
pattern1

Debounce

Wend
Joshua

Post Reply