I would like to know how one programs the control separate of 2 leds starting from

ritoonfr

New Member
Good day
I am initial in the programming of the picaxe (newbie)
I would like to know how one programs:
the control separate of 2 leds starting from 2 switches.
And possible Ci (feasible ease)
The ordering of a clock during the program flow which orders at the end of the program a led
For a picaxe 28x1.
Thank you for your answer
 

westaust55

Moderator
Welcome to the PICAXE forum

Have you had a read at the PICAXE manuals? :confused:

Manual 1 page 59 shows how to conenct and control one LED.
Not a great deal of changes to add a second LED on a second output.

Tutorial 5 on page 64 covers using a switch as an input and controlling (flashing an LED)

If you need more help, then you will need to give a more complete description of exactly what you wish to achieve.
As a starting point:
- which inputs for the switches
- which outputes ofr the LEDs
- when on, are the LED's to be on steady or flash?
- under what condition do you each LED to come on.
 
Last edited:

ritoonfr

New Member
Thank you for your answer.
I give you better indications.
A pressure on puchbutton 1: = led 1 lit permanently.
Another pressure on puchbutton 1: = led 1 extinct.
A pressure on puchbutton 2: = led 2 lit permanently.
Another pressure on puchbutton 2: = led 2 extinct.
A pressure on puchbutton 3: and led 3 and lit 1 minute afterwards during 10
seconds and dies out.
All the outputs must function even time.
A new pressure on one of the buttons: the sicle starts again.
Henri thanks.









Welcome to the PICAXE forum

Have you had a read at the PICAXE manuals? :confused:

Manual 1 page 59 shows how to conenct and control one LED.
Not a great deal of changes to add a second LED on a second output.

Tutorial 5 on page 64 covers using a switch as an input and controlling (flashing an LED)

If you need more help, then you will need to give a more complete description of exactly what you wish to achieve.
As a starting point:
- which inputs for the switches
- which outputes ofr the LEDs
- when on, are the LED's to be on steady or flash?
- under what condition do you each LED to come on.
 

BeanieBots

Moderator
These things tend to be very application specific.
In your case I would consider using interrupts to control the turning on/off of the LEDs and have a main loop which controls a counter/timer for controlling the LED timer.

The interrupt routine would load a counter and turn on LED 3.
The main loop would make many small decrements of the counter. When it reaches zero, turn off the LED.
 

ritoonfr

New Member
I seek code examples for this part.

A pressure on puchbutton 1: = led 1 lit permanently.
Another pressure on puchbutton 1: = led 1 extinct.
A pressure on puchbutton 2: = led 2 lit permanently.
Another pressure on puchbutton 2: = led 2 extinct.
 

lbenson

Senior Member
Code:
#picaxe 08m

main:
  do
    if pin3 <> bit0 then
      toggle 0
      bit0 = pin3
    endif
    if pin4 <> bit1 then
      toggle 1
      bit1 = pin4
    endif
  loop
Try it in the simulator. Read the manuals concerning the variables and commands used in the program. After reading, analyzing, and stepping through the program in the simulator, ask about anything you don't understand.

This assumes that the pushbuttons are on/off, not push-to-make. You can modify the code to make them act like push-to-make buttons by adding code to make sure that they go off before being activated again. In the real world, you might have to "de-bounce" your pushbuttons--either in code or with hardware.
 
Last edited:

ritoonfr

New Member
Super the example for the LED 1 and 2 corresponds to my program.

example Existe for the LED 3

(A pressure on puchbutton 1: = led 1 lit permanently.
Another pressure on puchbutton 1: = led 1 extinct.
A pressure on puchbutton 2: = led 2 lit permanently.
Another pressure on puchbutton 2: = led 2 extinct.)

A pressure on puchbutton 3: and led 3 and lit 1 minute afterwards during 10
seconds and dies out.

All the outputs must function even time.

A new pressure on one of the buttons: the sicle starts again.
Henri thanks.
 

lbenson

Senior Member
As Beaniebots suggested, one way to provide the timing you need is to use interrupts. Another way, if your timings can stand a little bit of leaway, is to have a master loop which pauses at the end for a short period period of time--say 100 milliseconds. Then you can use a loop counter to see when 600 100 millisecond loops have passed, giving you your one minute of on-time for led3. You need more i/o, so a 14M would be the minimum chip.

If you need to be really accurate, you may need a Real Time Clock (RTC) like the DS1307 (which requires I2C and an 18X or better chip). (Code not tested.)
Code:
main:
  do
    .
    .
    .
    if pin2 = 1 and bit2 = 0 then
      bit2 = pin2
      high 2
      b13 = 0
    endif
    if b13 > 599 then ' you have looped for about 1 minute
      bit2 = 0
      low 2
      b13 = 0
    endif
    pause 100
    if bit2 = 1 ' only count when led3 is on
      inc b13
    endif
  loop
Code to fade not included--search the forum for PWM and LED. Be prepared for lots of threads.
 
Top