|
Post by Rod on Jun 12, 2019 12:51:02 GMT -5
|
|
|
Post by themendist on Jun 14, 2019 4:57:30 GMT -5
Thanks again,
The original software has a lathe not connected warning which I thought I would add at some point but its not currently vital. I am making progress with the other code so happy for the time being.
Regards,
Keith
|
|
|
Post by themendist on Jul 10, 2019 3:19:58 GMT -5
Hi All,
Following my original post and help from the forum I seem to be making code progress with the control of the X and Z axes of the lathe.
I am now struggling to find a way of controlling the motor speed using the buttons in my code.
The lathe expects to see S200 to S2000 on the comm port 200 to 2000 RPM
I am trying to send the speed in increments of 100 RPM for every button press.
There are 2 buttons Speed UP and Speed DN.
Currently they send S200 and S2000 to the comm port which only gives me minimum and maximum speed.
This is the code for my current speed UP button.
[button12Click] 'Perform action for the button named 'button12'+S 'Insert your own code here
'print #comm, "S2000" +chr$ (13); wait
Thanks,
Keith
|
|
|
Post by metro on Jul 10, 2019 3:52:07 GMT -5
BMP.zip (948 B) 'contains the BMP's (3 of)
Hi Keith I am assuming print #comm, "S1000" +chr$ (13); would set the speed to 1000 and any "S(xxx)" will set the speed to xxx This is just a thought, I found this code some years back and am sure you could adapt it to have variable control not just 100rpm increments. '** Example of how to create a SLIDER control '** Excellent for making an input device with preset ranges '** Created by Triad Productions '** Feel free to modify this.... '** For better accuracy you could add arrow buttons on each side '** of the slider control.. These buttons could increment the '** Slider Value by a predetermined number.. '------------------------------------------------------------------ ' Original by Ryan Jefferies (circa 1997) ' Major re-write for Liberty Basic 2.02 and Liberty Basic 3.x. This ' version uses two bmp's that should be included in the zip file with ' this source. It is sprite based, giving clean, easy graphics. ' ' by Brad Moore - March 2002, Revised March 2004 ' ' -Again, as Ryan suggested - please use this freely. It is ' not intended to be an application unto itself. Incoporate into ' your code where ever a slider would enhance the UI. ' ' I tried to put enough comments into it to help people along. If ' you get stuck - give a holler on the LibertyBaisc Forum ' ' ' This is version 1.01, released 2/9/04 - Brad Moore ' ' Please consider this open source, I am sure this is the way Ryan ' intended it to be used and shared in the community. ' '-------------------------------------------------------------------
[slide.Entry] 'This is the slider entry point - gosub here to use the slider in your code...
'** Set up critical variables used during program execution ************************** ' 'Slider real value range - change these minimum and maximum values to allow the slider 'to select values of different ranges
SlideMin=200 'Minimum Slider Value (can be positive or negative) SlideMax=2000 'Maximum Slider Value (a value greater than SlideMin)
'These variables define the size of the graphicsbox and the way the slider operates
XMin(1)=0 'Current Cursor X-Min Position XMax(1)=13 'Current Cursor X-Max Position
MouseOffset = 4 'The offset for mouse movement on the graphic bar - improved effect
'The value 245 is used often here - it is the length of the graphicbox used for the slider
SLimitMin=0 'Minimum mouse location for left/right travel SLimitMax=245-MouseOffset 'Maximum mouse location for left/right travel SliderLen=245-MouseOffset 'Actual total pixels of slider area '(graphic box less pointer width and offset)
'You can set middle to any valid value you want by replacing this code - this sets the 'intial location of the thumb in the slider - most common at at the Min value, Max value 'middle value (which is where this code sets it)
Middle = Int((245-15)/2)+MouseOffset-1 'Center of slider - length of graphic 'window minus slider length ' divided by two and adjusted by offsets
'Determine granularity for sliding the thumb - store it in variable called slip slip = int(245/(SlideMax-SlideMin)) if slip < 1 then slip = 1
'Load the graphics used by the slider application into memory
LoadBmp "slider", "sliderm.bmp" LoadBmp "slide", "slidebar2.bmp"
NoMainWin '<-- You should already have this set in your code, comment this line out
WindowWidth = 330 WindowHeight = 110 'Set the location of the window as centered on the client screen UpperLeftX = Int((DisplayWidth-WindowWidth)/2) UpperLeftY = Int((DisplayHeight-WindowHeight)/2)
'** Add Window Controls Graphicbox #slide.Graphicbox1, 35, 25, 245, 15 Statictext #slide.StaticText1, "Slider Value=000", 98, 55, 130, 25 'Padded the X Value for unknown length Button #slide.SlideRight, "<",[slide.SlideRightClick],UL, 21, 25, 15, 15 Button #slide.SlideLeft, ">",[slide.SlideLeftClick],UL, 280, 25, 15, 15
'** Display window Open "Example: Slider Control" For Window As #slide
'Set a flag to track that this window is open SliderWindow = 1
'Trap window and graphic box events Print #slide, "TRAPCLOSE [slide.END]" Print #slide.Graphicbox1, "when leftButtonUp [slide.LMU]" Print #slide.Graphicbox1, "when leftButtonMove [slide.LMM]"
'Set the window default font Print #slide, "font ms_sans_serif 10"
'Load the sprite backgound into the graphic box Print #slide.Graphicbox1, "down;background slide"
'Load the slider sprite, define it as a sprite and make it visible Print #slide.Graphicbox1,"addsprite slider slider"; Print #slide.Graphicbox1, "spritevisible slider on"
'Set the intial mouse position to the center of the slider and call function to display MouseX = Middle 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen)
[slide.inputLoop] 'Scan for user events Wait
[slide.LMU] 'Left Mouse Button Up 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen) GoTo [slide.inputLoop] 'Check for more user events
[slide.LMM] 'Left Mouse Move 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen) GoTo [slide.inputLoop] 'Check for more user events
[slide.SlideRightClick] 'Check the bounds for the movement of the slider with the buttons If MouseX >= SLimitMax Then MouseX = SLimitMax-1 Else MouseX = MouseX - slip If MouseX <= 0 Then MouseX = 0 End If 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen) GoTo [slide.inputLoop] 'Check for more user events
[slide.SlideLeftClick] 'Check the bounds for the movement of the slider with the buttons If MouseX <= 0 Then MouseX = 1 Else MouseX = MouseX + slip If MouseX > SLimitMax Then MouseX = SLimitMax End If 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen) GoTo [slide.inputLoop] 'Check for more user events
[slide.END] 'This is the slider exit point. Close #slide 'In the demo I end the program execution. You will need to comment this out 'so that the RETURN statement will return program control to your program. End 'Reset the flag that tracks if Slider window is open SliderWindow = 0 return
Function mouseMove(MouseX,SlideMax,SlideMin,SLimitMax,SLimitMin,SliderLen)
'MouseX and MouseY represent cursor coordinates - we ignore MouseY 'The calculation for the Slider Value is calculated as follows.... ' '1) Current MouseX position divided by SliderLen (length of graphicbox minus offset for ' centering pointer) to yeild a percentage. ' '2) SlideMax-SlideMin gives the range of numbers... Which is multiplied by the percentage ' to determine a raw number ' '3) Add the value to the minimum range number to determine the actual number
If MouseX<=SLimitMin Then MouseX=SLimitMin 'Tried to move the mouse too far to the left If MouseX>=SLimitMax Then MouseX=SLimitMax 'Tried to move the mouse too far to the right
Print #slide.Graphicbox1, "spritexy slider ";MouseX-4;" 0" Print #slide.Graphicbox1, "drawsprites"
'Calculate Slider Value - More advanced calculation compensates for slider offset TempVar=Int((MouseX/SliderLen)*(SlideMax-SlideMin)+SlideMin)
mouseMove = TempVar
End Function
|
|
|
Post by themendist on Jul 10, 2019 4:56:27 GMT -5
'contains the BMP's (3 of)
Hi Keith I am assuming print #comm, "S1000" +chr$ (13); would set the speed to 1000 and any "S(xxx)" will set the speed to xxx This is just a thought, I found this code some years back and am sure you could adapt it to have variable control not just 100rpm increments. '** Example of how to create a SLIDER control '** Excellent for making an input device with preset ranges '** Created by Triad Productions '** Feel free to modify this.... '** For better accuracy you could add arrow buttons on each side '** of the slider control.. These buttons could increment the '** Slider Value by a predetermined number.. '------------------------------------------------------------------ ' Original by Ryan Jefferies (circa 1997) ' Major re-write for Liberty Basic 2.02 and Liberty Basic 3.x. This ' version uses two bmp's that should be included in the zip file with ' this source. It is sprite based, giving clean, easy graphics. ' ' by Brad Moore - March 2002, Revised March 2004 ' ' -Again, as Ryan suggested - please use this freely. It is ' not intended to be an application unto itself. Incoporate into ' your code where ever a slider would enhance the UI. ' ' I tried to put enough comments into it to help people along. If ' you get stuck - give a holler on the LibertyBaisc Forum ' ' ' This is version 1.01, released 2/9/04 - Brad Moore ' ' Please consider this open source, I am sure this is the way Ryan ' intended it to be used and shared in the community. ' '-------------------------------------------------------------------
[slide.Entry] 'This is the slider entry point - gosub here to use the slider in your code...
'** Set up critical variables used during program execution ************************** ' 'Slider real value range - change these minimum and maximum values to allow the slider 'to select values of different ranges
SlideMin=200 'Minimum Slider Value (can be positive or negative) SlideMax=2000 'Maximum Slider Value (a value greater than SlideMin)
'These variables define the size of the graphicsbox and the way the slider operates
XMin(1)=0 'Current Cursor X-Min Position XMax(1)=13 'Current Cursor X-Max Position
MouseOffset = 4 'The offset for mouse movement on the graphic bar - improved effect
'The value 245 is used often here - it is the length of the graphicbox used for the slider
SLimitMin=0 'Minimum mouse location for left/right travel SLimitMax=245-MouseOffset 'Maximum mouse location for left/right travel SliderLen=245-MouseOffset 'Actual total pixels of slider area '(graphic box less pointer width and offset)
'You can set middle to any valid value you want by replacing this code - this sets the 'intial location of the thumb in the slider - most common at at the Min value, Max value 'middle value (which is where this code sets it)
Middle = Int((245-15)/2)+MouseOffset-1 'Center of slider - length of graphic 'window minus slider length ' divided by two and adjusted by offsets
'Determine granularity for sliding the thumb - store it in variable called slip slip = int(245/(SlideMax-SlideMin)) if slip < 1 then slip = 1
'Load the graphics used by the slider application into memory
LoadBmp "slider", "sliderm.bmp" LoadBmp "slide", "slidebar2.bmp"
NoMainWin '<-- You should already have this set in your code, comment this line out
WindowWidth = 330 WindowHeight = 110 'Set the location of the window as centered on the client screen UpperLeftX = Int((DisplayWidth-WindowWidth)/2) UpperLeftY = Int((DisplayHeight-WindowHeight)/2)
'** Add Window Controls Graphicbox #slide.Graphicbox1, 35, 25, 245, 15 Statictext #slide.StaticText1, "Slider Value=000", 98, 55, 130, 25 'Padded the X Value for unknown length Button #slide.SlideRight, "<",[slide.SlideRightClick],UL, 21, 25, 15, 15 Button #slide.SlideLeft, ">",[slide.SlideLeftClick],UL, 280, 25, 15, 15
'** Display window Open "Example: Slider Control" For Window As #slide
'Set a flag to track that this window is open SliderWindow = 1
'Trap window and graphic box events Print #slide, "TRAPCLOSE [slide.END]" Print #slide.Graphicbox1, "when leftButtonUp [slide.LMU]" Print #slide.Graphicbox1, "when leftButtonMove [slide.LMM]"
'Set the window default font Print #slide, "font ms_sans_serif 10"
'Load the sprite backgound into the graphic box Print #slide.Graphicbox1, "down;background slide"
'Load the slider sprite, define it as a sprite and make it visible Print #slide.Graphicbox1,"addsprite slider slider"; Print #slide.Graphicbox1, "spritevisible slider on"
'Set the intial mouse position to the center of the slider and call function to display MouseX = Middle 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen)
[slide.inputLoop] 'Scan for user events Wait
[slide.LMU] 'Left Mouse Button Up 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen) GoTo [slide.inputLoop] 'Check for more user events
[slide.LMM] 'Left Mouse Move 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen) GoTo [slide.inputLoop] 'Check for more user events
[slide.SlideRightClick] 'Check the bounds for the movement of the slider with the buttons If MouseX >= SLimitMax Then MouseX = SLimitMax-1 Else MouseX = MouseX - slip If MouseX <= 0 Then MouseX = 0 End If 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen) GoTo [slide.inputLoop] 'Check for more user events
[slide.SlideLeftClick] 'Check the bounds for the movement of the slider with the buttons If MouseX <= 0 Then MouseX = 1 Else MouseX = MouseX + slip If MouseX > SLimitMax Then MouseX = SLimitMax End If 'Call mouseMove function to move slider and Display Slider Value Print #slide.StaticText1, "Slider Value=";mouseMove(MouseX,SlideMax,SlideMin,_ SLimitMax,SLimitMin,SliderLen) GoTo [slide.inputLoop] 'Check for more user events
[slide.END] 'This is the slider exit point. Close #slide 'In the demo I end the program execution. You will need to comment this out 'so that the RETURN statement will return program control to your program. End 'Reset the flag that tracks if Slider window is open SliderWindow = 0 return
Function mouseMove(MouseX,SlideMax,SlideMin,SLimitMax,SLimitMin,SliderLen)
'MouseX and MouseY represent cursor coordinates - we ignore MouseY 'The calculation for the Slider Value is calculated as follows.... ' '1) Current MouseX position divided by SliderLen (length of graphicbox minus offset for ' centering pointer) to yeild a percentage. ' '2) SlideMax-SlideMin gives the range of numbers... Which is multiplied by the percentage ' to determine a raw number ' '3) Add the value to the minimum range number to determine the actual number
If MouseX<=SLimitMin Then MouseX=SLimitMin 'Tried to move the mouse too far to the left If MouseX>=SLimitMax Then MouseX=SLimitMax 'Tried to move the mouse too far to the right
Print #slide.Graphicbox1, "spritexy slider ";MouseX-4;" 0" Print #slide.Graphicbox1, "drawsprites"
'Calculate Slider Value - More advanced calculation compensates for slider offset TempVar=Int((MouseX/SliderLen)*(SlideMax-SlideMin)+SlideMin)
mouseMove = TempVar
End Function
|
|
|
Post by themendist on Jul 10, 2019 5:05:38 GMT -5
Hi Metro, Thanks for your very quick reply. Unfortunately the space on my window is limited and I am trying to make my code look as close as possible to the original DOS control. I would prefer to use buttons if I can but I may take up your suggestion if I can find space. Your assumption that Sxxx is the speed is correct. The DOS software used a +S and -S button which are continuous in operation. The lathe works very well on the original DOS software using DOSBox in windows but it is very outdated and slow to set up. I'm sure I will get there in the end but my coding abilities are limited.
Thanks again,
Keith
|
|
|
Post by Rod on Jul 10, 2019 5:30:27 GMT -5
Something simpler then.
nomainwin WindowWidth = 400 WindowHeight = 400 UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2) textbox #1.tb, 100, 50, 200, 20 button #1.min, "Set Min", [setmin], UL, 100, 100, 200,20 button #1.nd, "Nudge Down ", [nudged], UL, 100, 130,200, 20 button #1.stop, "Stop ", [stop], UL, 100, 160, 200,20 button #1.nu, "Nudge Up ", [nudgeu], UL, 100, 190,200, 20 button #1.max, "Set Max ", [setmax], UL, 100, 220,200, 20
open "Speed Manager" for window as #1 print #1, "trapclose [quit]" revs=0 #1.tb revs wait
[setmin] revs=1000 gosub [setrevs] wait
[nudged] revs=revs-100 if revs<0 then revs =0 gosub [setrevs] wait
[stop] revs=0 gosub [setrevs] wait
[nudgeu] revs=revs+100 if revs>2000 then revs=2000 gosub [setrevs] wait
[setmax] revs=2000 gosub [setrevs] wait
[quit] close #1 end
[setrevs] 'print #comm, "S";str$(revs);chr$ (13); #1.tb revs return
|
|
|
Post by themendist on Jul 10, 2019 9:30:49 GMT -5
Hi Rod,
Thanks again I used some of your code with modifications to suit the names of my buttons. I now have stepped control of the motor speed.
Thanks again for your help,
Regards,
Keith
|
|