|
Post by huckster on Feb 14, 2019 20:29:55 GMT
Hi Forum, With Thanks and also Apologies to B+, who posted his crosshairs program in another thread. I massaged and abused that program and produced an on-screen mouse operated Joystick to use with an Arduino project. I have many years of programming but absolutely none with graphics; all industrial and embedded. So need a place to start, hence Crosshairs. I have it running and to enable entering a COM port number I am using a prompt box. Before I close this thing up and make it stand alone, I have a question... Is there a way in Just Basic to determine available com ports to be made available in a drop down? Thanks for any wisdom you can provide
Huck
I found coding the Joystick in Just Basic was ultimately easier than setting up the StepMotor controls in cpp for the Arduino.
|
|
|
Post by Rod on Feb 15, 2019 8:03:41 GMT
If you have a look at the LBPE and the article I wrote about the arduino you will find a chunk of code that searches out all available com ports and lists them in s combobox for the user to choose. alycesrestaurant.com/lbpe/Fun%20with%20the%20Arduino.htmlNot had time to test if it runs in Just BASIC but it works in Liberty BASIC Liberty BASIC can read a real joystick directly, not sure if that ported to JBv2
|
|
|
Post by Rod on Feb 15, 2019 8:55:11 GMT
Ok, it needed the sleep API fixed but I think this will run in Just BASIC now.
nomainwin 'We need an array to store the Com port names in dim port$(256) 'since we plan to use Subs we need a few globals 'I tend to identify global variables with a capital letter global Port Port=0
WindowWidth = 550 WindowHeight = 195 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) combobox #main.cbport, port$(, portClick, 5, 80, 50, 100 statictext #main.stport, "Com Port", 5, 60, 60, 20
open "Arduino simple interface" for window as #main #main "trapclose quit"
'find out what com ports are available and load the combobox call getPorts
'we need an endless loop to clear out the serial buffer while 1 scan 'call getresponse wend
'Subs to handle the com port ============================================== sub portClick h$ 'take com port combobox input, open choosen com port #main.cbport "selection? p$" if Port then close #port if p$<>"" then open p$;":9600,n,8,1,ds0,cs0,rs" for random as #port Port=1 call delay 500 end if end sub
sub getPorts 'test first 32 ports and load combobox list for valid serial ports index=1 for p = 1 to 32 oncomerror [trap] open "Com";str$(p);":9600,n,8,1,ds0,cs0,rs" for random as #com port$(index)="Com";str$(p) index=index+1 close #com
[trap] oncomerror next #main.cbport, "reload" 'now if there is only one port open it if port$(1)<>"" and port$(2)="" then open port$(1);":9600,n,8,1,ds0,cs0,rs" for random as #port Port=1 #main.cbport, "selectindex 1" call delay 500 else #main.cbport, "selectindex 0" end if end sub
sub delay m timer m, [done] wait [done] timer 0 'CallDLL #kernel32, "Sleep", m As ulong, Sleep As void end sub
sub quit h$ close #main if Port then close #port end end sub
|
|
|
Post by Rod on Feb 15, 2019 8:57:13 GMT
Oh and READJOYSTICK will get USB based joystick readings but I must find the code that B+ started you off with.
|
|
|
Post by huckster on Feb 15, 2019 20:33:10 GMT
Thanks Gentlemen! Will definitely give this a whirl. I'm not using a real joystick. What we are doing is trying to make a "Virtual Student" for a student unable to attend classes. So he needs to be able to control the "VS" via a remote connection while watching the webcam on the laptop atop the "VS". On Edit: This is where the crosshair program came from justbasiccom.proboards.com/thread/118/cross-hair
|
|
|
Post by huckster on Feb 16, 2019 0:43:02 GMT
It works! At least, I'm pretty sure it does. I don't have the Arduino at home and have only one FTDI USB adapter....which it identified and offers in the drop down list. The "try them all and see which ones howl" approach had never occurred to me. So, Monday will tell and Rod, thanks again for very timely assistance!
|
|
|
Post by huckster on Feb 16, 2019 3:34:05 GMT
It works! At least, I'm pretty sure it does. I don't have the Arduino at home and have only one FTDI USB adapter....which it identified and offers in the drop down list. The "try them all and see which ones howl" approach had never occurred to me. So, Monday will tell and Rod, thanks again for very timely assistance!
|
|