PDA

View Full Version : pic16f628a bike light controller-thought it would be easy...



Caddydan
- 12th February 2006, 06:44
Newbie here, I am trying to build a bike light controller to control the intensity of my homemade bike lights. What I am trying to accomplish is this:
1 Press button one time-turn light on to full intensity using hpwm.
2 Press button again(any time after first press)-lower intensity, lower pulse width.
3 Press button again-lowest intensity. Maybe 50% duty cycle.
4 Press and hold button for two seconds-light off.

I am having a hard time finding what commands to use-COUNT, RCTIME, lots of IF THEN and GOTO. It seems I can get close but no cigar. I have been using the PBP user manual and Chuck Hellebuyck's book Programming Pic Microcontrollers with PicBasic. I just do not have any programming experience to reference.

I am using PBP, Microcode Studio Plus, Picallw and the P16PRO40 programmer.
Note to other newbies: if your programmer has problems, try another computer-many manhours to make this observation.

Thanks to all for viewing and any help or direction you could provide.

Caddydan

Bill H
- 12th February 2006, 11:29
You have two things to keep track of not counting the HPWM portion.
1.) how many times the button is pressed.
2.) how long it is pressed.

Darrel Taylor has a great example of doing #2 in the memory button thread.

http://www.picbasic.co.uk/forum/showthread.php?t=3291

Here's how I see it being done.


check the button
is the button being held down?
yes or no
if yes, turn if off.
if no, is the light on full?
yes or no
if yes, dim it some
if no, is it 1st level dimmed?
yes or no
if yes, dim it some more
if no, is it second level dimmed?
yes or no
if yes, turn it back on full
if no, dim it some more


Bill H