remot control problem

Hi. I got some code problem in my 28x2. I am using picaxe ready made remot for my project. When i press a button it does the if command first and then put value in b0. So everytime i have to press twice the button to wright value in b0. Why is that happening? Please help. I am giving my commands bellow.

Irin c.0, b0
If b0 = 1 then
Let b0 = b1
Endif

If b0 = 16 and b1 = 1 then
Let b2 = b2+5
Endif

Now when press remot button 2, it puts 1 in b0, thats right. But when i press remot key up(which is 16) it does not add 5 in b2. When i press second time, it adds. Can you tell me whats wrong in my command please. Thanks
 

hippy

Ex-Staff (retired)
Let b0 = b1

Should that not be ...

Let b1 = b0

As 'b1' always remains zero it is not clear why it works the second time you press the key so I can only guess there is other code we are not seeing. Perhaps post your full code.
 

westaust55

Moderator
As hippy suggests, please post you full program code.
It could be that the program is not getting back to the IRIN command fast enough but we are guessing without seeing the entire program.
 
full code

Sorry guys i was really very busy at my work for last few days, i could not concentrate at my project. Anyway as you said, i posted my full code here. Please let me know what did i do wrong here. Is it the fequency froblem? But my 28x2 should adjust auto frequency, init?

#picaxe 28x2 *

symbol key_power = 21
symbol key_up = 16
symbol key_down = 17
symbol key_right = 18
symbol key_left = 19
symbol key_1 = 0
symbol key_2 = 1
symbol key_3 = 2
symbol key_4 = 3
symbol key_5 = 4
symbol key_6 = 5
symbol key_7 = 6
symbol key_8 = 7
symbol key_9 = 8
symbol key_0 = 9
symbol key_minus = 98
symbol key_plus = 11
symbol key_bar = 96
symbol key_tent = 54
symbol key_vert_cross = 37
symbol key_diag_cross = 20 * * * *


* main: *

irin c.1,b0

if b0 = key_1 then
let b0 = 0
let b1 = 0
let b2 = 0
endif * *

if b0 < 11 and b1 < 11 then
let b2 = 0
let b1 = b0
endif *

if b0 = key_power then *
sleep 1
goto main
endif *

if b0 = key_up and b1 = key_2 then
let b2 = b2 + 5
pulsout b.0,b2
endif *
goto main


I downloaded only these code on my motherboard. And its doing this problem so i didnt write rest of my code yet.
 

hippy

Ex-Staff (retired)
If you use SYMBOL definitions to name 'b0' 'thisKey' and name 'b1' as 'lastKey' it may become clearer why things are going wrong. You can run the program through Simulation to see what happens on receipt of each key press.
 

hippy

Ex-Staff (retired)
Go into File -> Options -> Simulation and ensure "simulate remote control for irin/infrain2" is ticked.

When you simulate the program a remote control pop-up will appear whenever the IRIN command is simulated. Set a breakpoint after that to step through the code.
 

MPep

Senior Member
Looking at your program, at what stage do variables B1 and B2 become anything else but 0??? The only input variable that gets assigned is B0, so I fail to understand you wanting to evaluate anything else.

Also, at the bottom of your program you have
Code:
[COLOR=#000000]if b0 = key_up and b1 = key_2 then [/COLOR]
IR remotes generally only allow one button press at a time. You cannot send 2 key presses simultaneously.

In the Simulator, I used Hippy's suggestion. Works well, didn't know about it before, because I haven't needed it.
For program evaluation, I added the following
Code:
b4 = b0 + 1
 sertxd (#b4,CR,LF)
just below the IRIN statement. Then in the Terminal you can see the buttons you pressed. I suggest further SERTXD statements for reading what's happening.

Code:
[COLOR=#000000]Irin c.0, b0[/COLOR]
[COLOR=#000000]If b0 = 1 then[/COLOR]
[COLOR=#000000]Let b0 = b1[/COLOR]
[COLOR=#000000]Endif[/COLOR]

[COLOR=#000000]If b0 = 16 and b1 = 1 then [/COLOR]
[COLOR=#000000]Let b2 = b2+5[/COLOR]
[COLOR=#000000]Endif[/COLOR]
This makes no sense to me as B0 = B1, yet you are evaluation B1 with a different value to B0 ?????
 
@ HIPPY simulation works perfectly.

As you told me, i did. Its working in simulation perfectly, but not in real project. I am bit confuse about one thing. That is, i used 3.3k resistor instead of 4.7k when i was installing parts at the IR sensor. Beacuse i didnt have that resister. Is this happening for that? Thanks
 
some body help please.

I changed that resistor. But it still read b0 lately. If it doesnt write on b0 at the same time when remot button pressed, how will perform rest of the command correctly? I dont know wat to do. Please help.
 

rossko57

Senior Member
Can you explain what happens, and what you are expecting to happen instead? Is your code still the same as the last listing you posted here?
 
@ Rossko57

Yes mate. Everything is same as it was. I just realized that , in simulation the commands are work perfectly. But when i download and test with remot i can see it dosent write on b0 when press a button. I am watching that on debug. For your refference you can see earler posts.
 

rossko57

Senior Member
But when i download and test with remot i can see it dosent write on b0 when press a button. I am watching that on debug.
When you started this thread, your code was responding to keypress, just not the way you expected. If it is not responding at all now, perhaps its simply time for new batteries in the remote.
Try a really simple program

debug so you can see what b0 is before any keypress
main:
irin c.0, b0
debug
goto main
 
it works !!!

Thanks guys it working now. I dont know what happend. I just changed bettary and shift the debug command at top. Thats it. Thank you somuch to all of you.
 
Top