simple flashlight LED - NEW to pic 12f629 -


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Talking

    itried to do the following.

    i have to buttons...one increase the brightness and the other decrease the brightness.

    but is not very smooth. I have also a problem to turn off the LED.

    For remind you, i need a code for making a flashligh like this:



    Code:
    @ DEVICE  PIC12F675,INTRC_OSC_NOCLKOUT ' internal RC osc
    @ DEVICE  PIC12F675,MCLR_OFF           ' Disable external MCLR
    @ DEVICE  PIC12F675,WDT_OFF            ' Disable WatchDog timer
    @ DEVICE  PIC12F675,PROTECT_OFF        ' Disable device protect
    @ DEVICE  PIC12F675,CPD_OFF            ' Disable Code-Protect
    INCLUDE "bs1defs.bas"
    ansel = 0            
    GPIO = 0
    TRISIO = %00001100 			' GP2 as input and set GP 0,1,3,4,5 as outputs
    CMCON  = 7
    ADCON0 = 0 ' A/D off      
    
    signal VAR BYTE
    signal=5
    Start:
          IF gpio.2=0 THEN
             signal=signal+1
             IF signal>10 THEN signal=10 
             pause 150
          ENDIF
          
          IF gpio.3=0 THEN
             signal=signal-1
             IF signal=255 THEN signal=0
             pause 150
          ENDIF      
          
          HIGH gpio.0
          PAUSE signal
          LOW gpio.0
          PAUSE (10 - signal)
          GOTO Start
    END
    you can see also there people trying....

    http://www.candlepowerforums.com/vb/...d.php?t=192206
    Last edited by astanapane; - 10th October 2010 at 10:01.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Here is something more. You will need to refine it.
    Code:
        CNT VAR BYTE
        BUT VAR GPIO.2
        LED VAR GPIO.1
        cnt = 0
          
        CHECK:
        IF BUT = 0 THEN TICK
        GOTO CHECK   
        
        TICK:
        PAUSE 100
        CNT = CNT + 1
        IF cnt = 1 THEN DIM
        IF cnt = 2 THEN BRIGHT
        IF CNT => 3 THEN LED_OFF
        GOTO CHECK
        
        DIM:
        PWM LED,75,100  
        IF BUT = 0 THEN TICK
        GOTO DIM
        
        BRIGHT:
        HIGH LED
        PAUSE 100
        IF BUT = 0 THEN TICK
        GOTO BRIGHT
        
        LED_OFF:
        LOW LED
        PAUSE 250
        CNT = 0
        GOTO CHECK
        
        end
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default

    Thank you mackrackit,

    i will try the code later and let you know. When i finish the circuit and the code i will post it here.

    Regards

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts