Problem with led


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    I test now and it's work (thanks to skimask) , but when i press the 0 turn off both leds.
    I want if i press one time the 1 to turn the led1 on and if i press again the 1 to turn off the led1.The same for the led2
    Have you tried the toggle command?

  2. #2
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Have you tried the toggle command?
    No.
    I try now with toggle and work.
    Thank you.
    I add this:
    if new = 1 then toggle led1
    if new = 2 then toggle led2
    The only problem now is :
    when power up for the first time , i must press the number 2 > enter and again the number 2 > enter to turn the led on (only for number 2 - not for number 1)
    After this no need second time to press the number 2.
    Last edited by savnik; - 17th January 2007 at 13:13.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    No.
    I try now with toggle and work.
    Thank you.
    I add this:
    if new = 1 then toggle led1
    if new = 2 then toggle led2
    The only problem now is :
    when power up for the first time , i must press the number 2 > enter and again the number 2 > enter to turn the led on (only for number 2 - not for number 1)
    After this no need second time to press the number 2.
    Have you no imagination? No creative thoughts?

    CMCON = 7
    ANSEL = 0
    adcon.1 = 7

    new var byte
    led1 var PORTA.2
    led2 var PORTA.3

    main:
    new = 0
    serout porta.0, T9600, ["Enter which LED to light (1-2,0=Off): ", 10, 13]
    serin porta.1, T9600, new
    serout porta.0, T9600, ["LED Chosen: ", new, 10, 13]

    if new = "1" then

    if led1 = 1 then
    led1 = 0
    else
    led1 = 1
    endif

    endif

    if new = "2" then

    if led2 = 1 then
    led2 = 0
    else
    led2 = 1
    endif

    endif

    if new = "0" then
    low led1 : low led2
    endif

    goto main

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Set the value . .

    Quote Originally Posted by savnik View Post
    No.
    I try now with toggle and work.
    Thank you.
    I add this:
    if new = 1 then toggle led1
    if new = 2 then toggle led2
    The only problem now is :
    when power up for the first time , i must press the number 2 > enter and again the number 2 > enter to turn the led on (only for number 2 - not for number 1)
    After this no need second time to press the number 2.
    Hi Savnik,
    in your code do this, put your code into nice little chunks that you can see what they do. Chunk1 put all your defines and variable declarations.
    chunk 2 is start directory. chunk 3 is main loop. this will help you stay organised.In the start subdirectory give your variables a set value,
    I think this should help.

    Code:
    CMCON = 7
    ANSEL = 0
    adcon.1 = 7
    
    new var byte
    led1 var PORTA.2
    led2 var PORTA.3
    
    Start:
    led1 = 0
    led2 = 0
    
    main:
    new = 0
    serout porta.0, T9600, ["Enter which LED to light ", 10, 13]
    serin porta.1, T9600, new
    serout porta.0, T9600, ["LED Chosen: ", new, 10, 13]
    
    if new = "1" then
    
    if led1 = 1 then
    led1 = 0
    else
    led1 = 1
    endif
    
    endif
    
    if new = "2" then
    
    if led2 = 1 then
    led2 = 0
    else
    led2 = 1
    endif
    
    endif
    
    if new = "0" then
    low led1 : low led2
    endif
    
    goto main
    The commands in the start directory will run only once at startup and should set both leds in the off condition.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Hi Savnik,
    in your code do this, put your code into nice little chunks that you can see what they do. Chunk1 put all your defines and variable declarations.
    chunk 2 is start directory. chunk 3 is main loop. this will help you stay organised.In the start subdirectory give your variables a set value,
    I think this should help.

    Code:
    CMCON = 7
    ANSEL = 0
    adcon.1 = 7
    
    new var byte
    led1 var PORTA.2
    led2 var PORTA.3
    
    Start:
    led1 = 0
    led2 = 0
    
    main:
    new = 0
    serout porta.0, T9600, ["Enter which LED to light ", 10, 13]
    serin porta.1, T9600, new
    serout porta.0, T9600, ["LED Chosen: ", new, 10, 13]
    
    if new = "1" then
    
    if led1 = 1 then
    led1 = 0
    else
    led1 = 1
    endif
    
    endif
    
    if new = "2" then
    
    if led2 = 1 then
    led2 = 0
    else
    led2 = 1
    endif
    
    endif
    
    if new = "0" then
    low led1 : low led2
    endif
    
    goto main
    The commands in the start directory will run only once at startup and should set both leds in the off condition.



    Now why didn't I think of that

  6. #6
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default now work

    thanks skimask and Joe S.

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. Flashing!! LED Dot matrix problem
    By chai98a in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th December 2006, 09:45

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