simple flashlight LED - NEW to pic 12f629 -


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2010
    Posts
    411

    Talking simple flashlight LED - NEW to pic 12f629 -

    hello all,

    i'm very happy that i found you site. I'm very new to PbP programming. Actually i have very basic knowledge and would like ta have some help if you have time.

    So lets start from what i have in mind to do.

    1)I would like to use at first the PIC12f629.

    2)I need to use one button.

    3)and one LED

    Now.... i want to press the button and light the LED on 10 % of brightness

    then to press it again and light it to 50 % and then press again and light it to 100%

    At the end if i press it once more to turn off the LED.

    Actually if it is simple enouph i would like to turn the led off if i press the button more that 3 seconds.

    If this is very difficult to do please do not be bother to help me i dont want to disturb you. But if anyone have time i would be very please.

    What i have done till now is not a lot.

    I have turned on an LED and turned off.

    Then i can use PWM GPIO.0,a + 1,2 to light the LED but none more.

    I have also an other problem that i cannot turn on with PWM command more that one GPIO.

    For example i would like to turn on the LED from 0 to 255 and then from 255 to 0 but on the port GPIO.0, GPIO.1 and GPIO.2, how can i do that?

    Thank you very much for your help in advance.

    Best Regards

    astanapane.

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


    Did you find this post helpful? Yes | No

    Default

    Welcome to the forum.

    Lets look at the counting part first.
    You will need a variable
    CNT VAR BYTE

    Then when ever the button is pressed
    CNT = CNT + 1

    IF CNT equals x then z.

    Here is a similar thread you may want to read
    http://www.picbasic.co.uk/forum/showthread.php?t=13744
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default

    thank you very much.

    I will check - read and come back.

  4. #4
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default

    On the following code, which the 100% i took it from the link you already gave me, i manage to place my won PWM code.

    The problem is that i cannot make the LED to stay at the specific brightness i gave to the PWM.

    Also at the moment it is also difficult for me to place more than one britghness.

    As i told you i would like to make the button to control one led but when i press once the button to have 10% of brightness then press again and have 50% and then pressed again 100%.

    If there is any help for this please, and i will keep trying to understand better the sequence of debounch.

    thank you again for your help.

    Best regards.

    INCLUDE "bs1defs.bas"

    DEFINE OSC 4


    cnt VAR BYTE
    delay var byte

    boton VAR GPIO.2
    led VAR GPIO.1

    ANSEL = 0 '12F675 for test
    CMCON = 7
    OPTION_REG.7= 0 'Pullups enabled
    WPU = %00000100

    steps VAR WORD
    cycles CON 2

    cnt = 0
    GPIO = %00000110 ' Nosurprise startup ...
    TRISIO = %00000100 ' GP2 as input and set GP 0,1,3,4,5 as outputs

    '************************************************* *****************************
    Detect: 'Button presses W/Debounce
    '
    delay = 0
    BUTTON Boton ,1,255,0,delay,0,pressed
    'Pin,Down,Delay,Rate,BVar,Action,Label
    ' Slow Things down
    GOTO Detect
    '************************************************* *****************************
    Pressed: ' Some > 10ms press detected
    IF cnt <=1 Then 'tocount uptu 3, bigger values will add up.

    cnt = cnt + 2

    ELSE

    cnt = 0
    For steps=0 TO 100
    PWM led,steps,cycles
    Next
    'in here what can i type in order the LED to stay at the specific brightness???
    ENDIF

    WHILE !Boton : WEND ' Wait Boton release !!!
    goto detect

    END

  5. #5
    Join Date
    Oct 2010
    Posts
    411


    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.

  6. #6
    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.

  7. #7
    Join Date
    Oct 2010
    Posts
    411


    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 : 1

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