Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:10 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : uMite + Parallax Hackable Badge

     Page 4 of 4    
Author Message
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 10:10pm 22 Dec 2015
Copy link to clipboard 
Print this post

Sorry, two more things that could be the cause of your issue:

1: Why is SUB ShowIt(x) simply not called ShowIt. There is no need to pass (x) as within the sub you are using a 'For x = .....' loop. If I am correct, simply call the sub ShowIt (and make relevant change to the call from the IR_Int code).

2: In your IR_Int sub, you are using the variable x as a 'counter' to then calculate the value of y. If the incoming keycode is 99 you go off and call ShowIt and then ShowIt2. In both these subs you use x as the 'loop index' value (i.e. For x = ......). IF there was some 'unexpected' trigger for the IR_Int sub to be called again at anytime then the value of x would be incorrect.
Solution: In your two ShowIt subs, use another unused variable instead such as: For i = ....., grabIR(i), Next i
But leave 'x' in the IR_Int sub.

This way they won't 'corrupt' each other.

WW
 
dasyar
Regular Member

Joined: 13/04/2015
Location: United States
Posts: 58
Posted: 11:37am 23 Dec 2015
Copy link to clipboard 
Print this post

Thanks WW for the suggestions.

Below I have my latest update, which runs as expected. But I am now picking up and displaying a '1'. I see the vertical and horizontal printout is to be expected, but it is printing out the '1', and I cannot figure out where that is occurring.

In the showIt2 SUB, I am leaving the 'Print' statements in for the time being, I am using that as sort of a debug tool. I am slowly adding the uppercase and special characters to the SUB also. Once I get this to a point where I think it is working without any surprises than I will start to remove some of the debug things.

I still have not decided whether I want to go with a large buffer for capturing the IR code, or make it small, maybe ten or fifteen character element.

  Quote  
Saved 3639 bytes
> run
43
14
21
21
24
99
43 14 21 21 24 99 0
Hello;
1
Hello;1
45
24
17
23
39
24
14
99
45 24 17 23 39 24 14 99 0
JohnDoe;
1
Hello;1JohnDoe;1
>




' testInc
' December 19, 2015

' Global
DIM grabIR(20) ' Array with 21 elements
DIM convertedIR$
DIM i,j
DIM x = 0
'DIM Hello$
'DIM JohnDoe$
''''''''''

' Start the IR interrupt
IR DevCode, KeyCode, IR_Int


' Main program body
DO
' Print convertedIR$
' Pause 3000
LOOP

END
''''''''''

' The sub for the IR interrupt
IR_Int:
' Show actual of incoming
'PRINT "Received device = " DevCode " key = " KeyCode

'Print "x = " x

grabIR(x) = KeyCode ' KeyCode for specified elemnt
Print grabIR(x) ' Print the value with the specific element
x = x + 1 ' Increment x

if KeyCode = 99 then ' If eol
j = x ' Last increment before eol
showIt ' Show individual elements
Print "" ' A CR
showIt2 ' Show the interpreted elements
Print "" ' A CR

x = 0 ' Sets x to 0, and over writes existing elements
Print convertedIR$ ' This a string
endif

IRETURN
''''''''''

SUB showIt
For i = 0 to j
' For x = 0 to y ' Start with first element of grabIR()
Print grabIR(i); ' Print all the integer elements
' next x
Next i
END SUB

''''''''''

' The interpreter sub
' Show the contents of grabIR(x) interpreted
SUB ShowIt2
'ccon$ = ""
' For x = 0 to y
For i = 0 to j
'PRINT grabIR ' Print the array of numbers
' SELECT CASE grabIR(x)
SELECT CASE grabIR(i)
CASE 0
PRINT "1";
ccon$ = "1"
CASE 1
PRINT "2";
ccon$ = "2"
CASE 2
PRINT "3";
ccon$ = "3"
CASE 3
PRINT "4";
ccon$ = "4"
CASE 4
PRINT "5";
ccon$ = "5"
CASE 5
PRINT "6";
ccon$ = "6"
CASE 6
PRINT "7";
ccon$ = "7"
CASE 7
PRINT "8";
ccon$ = "8"
CASE 8
PRINT "9";
ccon$ = "9"
CASE 9
PRINT "0";
ccon$ = "0"
CASE 10
PRINT "a";
ccon$ = "a"
CASE 11
PRINT "b";
ccon$ = "b"
CASE 12
PRINT "c";
ccon$ = "c"
CASE 13
PRINT "d";
ccon$ = "d"
CASE 14
PRINT "e";
ccon$ = "e"
CASE 15
PRINT "f";
ccon$ = "f"
CASE 16
PRINT "g";
ccon$ = "g"
CASE 17
Print "h";
ccon$ = "h"
CASE 18
PRINT "i";
ccon$ = "i"
CASE 19
PRINT "j";
ccon$ = "j"
CASE 20
PRINT "k";
ccon$ = "k"
CASE 21
PRINT "l";
ccon$ = "l"
CASE 22
Print "m";
ccon$ = "m"
CASE 23
PRINT "n";
ccon$ = "n"
CASE 24
PRINT "o";
ccon$ = "o"
CASE 25
Print "p";
ccon$ = "p"
CASE 26
Print "q";
ccon$ = "q"
CASE 27
Print "r";
ccon$ = "r"
CASE 28
Print "s";
ccon$ = "s"
CASE 29
Print "t";
ccon$ = "t"
CASE 30
Print "u";
ccon$ = "u"
CASE 31
Print "v";
ccon$ = "v"
CASE 32
Print "w";
ccon$ = "w"
CASE 33
Print "x";
ccon$ = "x"
CASE 34
Print "y";
ccon$ = "y"
CASE 35
Print "z";
ccon$ = "z"
CASE 39
Print "D";
ccon$ = "D"
CASE 43
PRINT "H";
ccon$ = "H"
CASE 45
Print "J";
ccon$ = "J"
CASE 99
PRINT ";"
ccon$ = ";"
END SELECT
convertedIR$ = convertedIR$ + ccon$
ccon$ = ""
Next i

END SUB
''''''''''
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 12:04pm 23 Dec 2015
Copy link to clipboard 
Print this post

When you like, you can make that vastly shorter and simpler.

You look to be converting numbers (here, smallish ones that fit in a byte) into single characters, so MID$ can help. Like
ccon$ = MID$("1234567890abcdef...", grabIR(i) + 1, 1)
print ccon$

(You seem to count from 0 but I think MID is from 1.)

Looks like you won't need the CASE at all.

You can either put dummy chars in the long string for MID$ (to get to 99) or use an IF.

JohnEdited by JohnS 2015-12-24
 
dasyar
Regular Member

Joined: 13/04/2015
Location: United States
Posts: 58
Posted: 02:16am 24 Dec 2015
Copy link to clipboard 
Print this post

A bit of a problem making a filled integer element array blank. In the code below, I use 'grabIR(x) = 0' to try to make the array blank, but as shown in the print out, that is not doing it. I looked through the manual and did not see anything specific as to how to do this. What should I be doing?



If KeyCode = 99 Then
j = x - 1
showIt ' Show the integer elements
Print ""
showIt2 ' Show the converted elements
Print ""
Print convertedIR$ ' Show the string
grabIR(x) = 0 ' Make integer element array blank???
Print grabIR(x) ' This should be empty ???
x = 0
Endif

grabIR(x) = KeyCode ' KeyCode for specified elemnt
Print grabIR(x) ' Print the value with the specific element
x = x + 1 ' Increment x


  Quote  
Saved 3867 bytes
> run
43
14
21
21
24
43 14 21 21 24
Hello
Hello
0
99
45
24
17
23
39
24
14
99 45 24 17 23 39 24 14
;
JohnDoe
Hello;JohnDoe
0
99
>
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:37am 24 Dec 2015
Copy link to clipboard 
Print this post

You reset the index x to 0 so the entry GrabIR(0) is printed the second time.

Edited by MicroBlocks 2015-12-25
Microblocks. Build with logic.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 02:45am 24 Dec 2015
Copy link to clipboard 
Print this post

Basic will be doing as it's told. What it's being told looks... suspect.

it's starting to look like my MID example could use KeyCode instead of GrabIR...

John
 
dasyar
Regular Member

Joined: 13/04/2015
Location: United States
Posts: 58
Posted: 03:22am 24 Dec 2015
Copy link to clipboard 
Print this post

  Quote  
You reset the index x to 0 so the entry GrabIR(0) is printed the second time.

I just tried that, and it did not do the job. It looks like you need to do something like grabIR(x) = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} to make all the elements 0 and the array sort of empty. For a small array this may not be to cumbersome, but for a larger array, 256 elements, I guess you would have to set up some kind of SUB. Now I am wondering if you have a sting array, would you have to do the same thing for that also?

@JohnS, I am using the CASE strategy to convert integer elements that you receive with KeyCode to a char representation, otherwise all you have are integers, which do not represent ascii or anything else.
 
dasyar
Regular Member

Joined: 13/04/2015
Location: United States
Posts: 58
Posted: 04:04am 24 Dec 2015
Copy link to clipboard 
Print this post

  Quote  
grabIR(x) = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} to make all the elements 0

That strategy did not work. I guess I am trying to change an existing DIM variable, anyway it comes back with a 'Invalid syntax' error. Now I am stumped again, not sure how to set grabIR(x) to empty, short of creating a SUB to do that, I thought there would be an easier way to accomplish this.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 05:36am 24 Dec 2015
Copy link to clipboard 
Print this post

  dasyar said  @JohnS, I am using the CASE strategy to convert integer elements that you receive with KeyCode to a char representation, otherwise all you have are integers, which do not represent ascii or anything else.

Exactly what I showed how to do. In effect you can treat a string as a char array, indexed by MID$

Your previous code doesn't appear to need GrabIR at all but if you keep it then it also doesn't appear to need its elements set to zero. Use a loop to do that if you wish.

JohnEdited by JohnS 2015-12-25
 
dasyar
Regular Member

Joined: 13/04/2015
Location: United States
Posts: 58
Posted: 01:42am 25 Dec 2015
Copy link to clipboard 
Print this post

After giving it some thought, this Christmas Day morning, I have decided to abandon the uMite IR aspect of my recent coding experiment. I get this deep nagging feeling, that after all is said and done, I will not be happy with the result. So, on to other things.

I will still try to pursue the use of the uMite in a form of, maybe logging some temp modules and then moving the data over to the RPi for processing. This might be more to my level of MMbasic programming skills. Now I will probably get back to finishing up on my experimental code to have a good workable solution for doing comms with the RPi.

Merry Christmas to everyone.
 
     Page 4 of 4    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025