Infra code adjustment

jlhooper

New Member
I have an IR "pair" : 08m Rxer and 08m Txer.
These are using the attached code and working great.
Each button push turns on a led, this then stays "latched" until another button is pushed,
which then turns on another led in it's place.
After any button push one led always remains on.

What I wish to do is to have a led turn on whilst the Tx button is depressed, and then turn off when the Tx button is released. Along the lines of a + - vol control.

I've been playing around with the code but have now lost patience and it's driving me nuts !!
Any help would be greatly appreciated.
Jeff
 

Attachments

Chavaquiah

Senior Member
On a real remote, when a button is kept down there is not quite a continuous signal sent but rather - as your sending code already does - a series of discrete signals is sent in succession.

The 08M cannot, thus, know when a button has been released. All it knows is that signals keep arriving. But it also cannot stop an infrain command, even if no more signals come in...

In a way, this does help your project. Simply turn off all LEDs before returning from your lightx subroutines. Include a small pause to keep the LED on for a little while.

If the user keeps pressing the same button, the receiver will keep lighting the same LED, almost giving the appearance of it being always on.

Now, SIRC signals are not terribly fast. There will be a blinking effect as the LED keeps turning on and off. Perhaps a capacitor might help in smoothing things out. But I'll leave this to someone who actually knows something about electronics.

An alternative might be a 555 based timer to keep the LED on...
 

Pauldesign

Senior Member
Although, i haven't tested codes practically, the enclosed IR Tx and Rx O8M codes might do the trick. For just one shot application, you may remove the STAY_ON and STAY_OFF subroutines.

If button is depressed for less than 3S, a 1 will be transmitted to turn on LED on Receiver and if still depressed after 3s or release, a zero will be transmitted to turn off LED in Receiver.

IR Transmitter:

Code:
Symbol Switch_OFF = b0
Symbol Switch_ON  = b1
Symbol Counter    = b2

Let Counter    = 0
Let Switch_OFF = 0
Let Switch_ON  = 1


Main:

toggle 0
if pin1 = 1 then: gosub Transmit endif; read input pin1 when push button is depressed (u have to connect pin1 to Vcc via a 4k7 pull up resistor)
debug
goto main 


Transmit:
        
        Let Counter=0;Let Counter=0 ;initialize counter after loop is over     
        do while Counter<5 ;process loop as long as b0 value is less than 3 
        inc Counter; increase b0 by 1
        wait 1
        if Counter<3 then: gosub Transmit_1 elseif Counter>3 then gosub Transmit_0 endif
        loop ;repeat do condition
          return ;return from this subroutine to stack
    
Transmit_1:

high 0
serout 0, T2400,("PRESS",#Switch_ON)
pause 50
return


Transmit_0:

low 1
serout 0, T2400, ("PRESS",#Switch_OFF)
return

IR Receiver:
Code:
Symbol Power_OFF = b0
Symbol Power_ON  = b1
Symbol Request   = b2


Let Power_OFF =0
Let Power_ON = 1


Transmit:

toggle 1
serin 3,T2400,("PRESS"),Request
if Request=1 then: gosub Transmit_1 elseif Request=0 then gosub Transmit_0 endif
debug
goto Transmit

	
Transmit_1:

high 1; If LED is connectted to pin 1, it will light
wait 1; adjust delay for how long you want it high
if Request=1 then: gosub Stay_ON endif
return


Transmit_0:

low 1; turn LED off
wait 1; adjust delay for how long you want it high
if Request=0 then: gosub Stay_OFF endif
return


Stay_ON:

high 1
return

Stay_OFF:

low 1
return
If the enclosed TX and Rx codes doesn't do what you wanted (from my understandings, you want the receiver 08M chip outpin to stay on all the time upon receiving a high instruction (logic 1) from the TX and vice versa) then play around with the code a bit.

And if that doesn't still, consider using a 20x2 or 18M2 chips that support latch actions or google and invest in a Latch chip or Flip-Flip IC. If done properly both code wise and hardware connections, it should work all the time.

Tip: Connect the output pin of the Rx Picaxe to the input of the Latch device and the output from the Latch device will acts based on the input pin transition. (i.e if input pin is high, output will stay high (thus high latch) and vice versa). If input pin is low, output will stay low (thus low latch) as hence flip-flop. Note, Latch and Flip-flop devices does the same things but operate differently. You may google for detail operations if interested.

You're welcome for further questions. ;)
 

hippy

Ex-Staff (retired)
Code:
#Picaxe 08M

' LED on output 1
' TSOP18 IR Receiver to input pin 3

Main:
    Gosub ReadInfra
    High 1
    Goto Main
   
ReadInfra:
  If pin3 <> 0 Then
    If b0 = 0 Then
      Low 1
    Else
      b0 = b0 -1
    End If
    Goto ReadInfra
  End If    
  b0 = 100
  InfraIn2
  Return
 
Top