locked
Small Basic Joystick / Game Controller Extension v0.3 RRS feed

  • General discussion

  • I have written an extension to use any joystick / game controller / racing wheel / etc. with Small Basic. It is pretty slow as is, so optimizations should be coming soon. It is written in C# with SlimDX, a wrapper for DirectX with managed code. I welcome anyone to decompile and improve upon it. I have added XML documentation, so parameters, returns, etc. will be built in to Small Basic. Suggestions are also welcome.

    Download link: http://www.mediafire.com/download.php?qbbt7j2m23gruzn and prerequisite:  http://slimdx.googlecode.com/files/SlimDX%20Runtime%20.NET%202.0%20%28January%202012%29.msi.

    Beginners can use the  JoystickForSmallBasic class while more advanced users can use the MUCH faster JoystickForSmallBasicAdvanced class (just don't foget to Acquire() at the beginning and Unacquire() at the end if you use the advanced version).

    Also, please be warned that the extension does not set a Cooperative Level with other DirecX input devices, so keyboard and mouse input may be interrupted while information is being retrieved from the joystick (this is because SetCooperativeLevel requires calling from a static method).

    (Credit to http://shahardev.blogspot.com/2011/10/talking-to-joysticks-using-slimdx.html for code on how to acquire joysticks)






    • Edited by gungan37Editor Sunday, August 12, 2012 3:15 AM Corrected "DirecX" to "DirectX"
    Wednesday, August 8, 2012 3:50 AM
    Answerer

All replies

  • any Idea what this is?


    Zock77


    Wednesday, August 8, 2012 4:25 AM
    Answerer
  • Hi Zock77!

    There are really two possibilities to solve this problem.

    1) Did you copy all 4 files from the Zip archive? All 4 files are necessary.

    2) If copying all the files didn't work, install this http://slimdx.googlecode.com/files/SlimDX%20Runtime%20.NET%202.0%20%28January%202012%29.msi (the prerequisites for SlimDX, the DirectX Wrapper I used).

    Wednesday, August 8, 2012 2:07 PM
    Answerer
  • That fixed it!! Thanks! i'll use that!

    Zock77


    Wednesday, August 8, 2012 4:09 PM
    Answerer
  • Glad it worked! Was it the first step or the second that fixed it?
    Wednesday, August 8, 2012 4:37 PM
    Answerer
  • The second

    Zock77

    Wednesday, August 8, 2012 8:08 PM
    Answerer
  • Is there any way I can make it faster?


    Zock77

    Wednesday, August 8, 2012 9:38 PM
    Answerer
  • Yes, I can write it so that it does not acquire the joystick then unacquire it after every poll. However, this could cause issues for beginners who do not acquire the joystick first then unacquire it an free its resources afterwards. What I will do (probably this afternoon) is make an advanced version that allows for acquiring / unacquiring to increase speed.
    Wednesday, August 8, 2012 10:33 PM
    Answerer
  • Version 3 is out now, with a class for advanced users (JoystickForSmallBasicAdvanced) that allows for VERY FAST reading of the game controller. Just don't forget to call Acquire() at the beginning of the program and Unacquire() at the the end. 
    Wednesday, August 8, 2012 11:08 PM
    Answerer
  • How do i get it?

    Zock77

    Thursday, August 9, 2012 1:46 AM
    Answerer
  • It is in the main thread. The link is http://www.mediafire.com/download.php?qbbt7j2m23gruzn and it contains both the advanced and beginner versions.
    Thursday, August 9, 2012 2:35 AM
    Answerer
  • PKH977 works pretty well for a test.

    Zock77

    Thursday, August 9, 2012 4:13 AM
    Answerer
  • Nice test! It works very well. I also have written TextWindow-based FGM626 for my own use when I was developing the extension.
    Thursday, August 9, 2012 4:29 PM
    Answerer
  • Hello,

    I am a bit embarrassed, I want to use your app in order to use a Xbox controller to control a Lego EV3 robot but your extension doesn't seem to work with the EV3 basic extension.

    SO i already had the EV3 extension when I tried to install yours. I downloaded SlimDX, installed it. then I downloaded your zip archive with all the files. I copied all the files in the C:\Program Files (x86)\Microsoft\Small Basic\Lib directory and it doesn't seem to work the Joystick classes don't appear in small basic.

    Did I do something work or there is a compatibility problem with the EV3 extension?

    If you could please answer my question fast it would be perfect.

    thank you very much.

    Friday, November 20, 2015 8:29 PM
  • That is because this extension was built for SB version 1.0 and you are running version 1.2

    This extension needs to be rebuilt.


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Friday, November 20, 2015 9:07 PM
    Answerer
  • how and can someone knowing his stuff can do that for me or do I have to dowload the 1.0 version of everything wich means that it will be complicated i guess?
    Friday, November 20, 2015 11:29 PM
  • I know how to do this, but I'd need the source code for that. I'll search around for that.

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Saturday, November 21, 2015 2:32 AM
    Answerer
  • that is very kind of you, as a mechanical engineer I thank you. Coding is really not my cup of tea.
    Saturday, November 21, 2015 3:18 AM
  • Okay if someone better then me at this would help, it would be appreciated.

    I have use ILspy to decompile the code, then I added it to VB and fixed some errors, but the code won't run in SB.

    I am using .net 4.5, so that isn't the issue.

    here is the code:

    Imports Microsoft.SmallBasic.Library
    Imports SlimDX.DirectInput
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    
    ''' <summary>
    ''' An extension to help clean up my code
    ''' </summary>
    ''' 
    
    <SmallBasicType()>
    Public Module JoystickSB
    
        Private js As JoystickState = New JoystickState()
    
        Private m_joystickDevice As Joystick
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' The number of axes on the first game controller.
        ''' </summary>
        Public ReadOnly Property AxesCount() As Primitive
            Get
                Return JoystickSB.m_joystickDevice.Capabilities.AxesCount
            End Get
        End Property
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' The number of buttons on the first game controller.
        ''' </summary>
        Public ReadOnly Property ButtonCount() As Primitive
            Get
                Return JoystickSB.m_joystickDevice.Capabilities.ButtonCount
            End Get
        End Property
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the firmware revision of the first joystick
        ''' </summary>
        ''' <returns>The version number of the firmware</returns>
        Public ReadOnly Property FirmwareRevision() As Primitive
            Get
                Return JoystickSB.m_joystickDevice.Capabilities.FirmwareRevision.ToString()
            End Get
        End Property
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' The number of poPrimitive-of-view (POV) hats on the first game controller.
        ''' </summary>
        Public ReadOnly Property POVCount() As Primitive
            Get
                Return JoystickSB.m_joystickDevice.Capabilities.PovCount
            End Get
        End Property
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Acquire the first joystick / game controller. This must be done before polling the joystick.
        ''' </summary>
        Public Sub Acquire()
            Dim directInputList As List(Of DeviceInstance) = New List(Of DeviceInstance)()
            Dim directInput As DirectInput = New DirectInput()
            directInputList.AddRange(directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            JoystickSB.m_joystickDevice = New Joystick(directInput, directInputList(0).InstanceGuid)
            JoystickSB.m_joystickDevice.Acquire()
            JoystickSB.SetAxisRange()
        End Sub
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the state of the button with a given index
        ''' </summary>
        ''' <param name="Index">The number of the button (starting with zero)</param>
        ''' <returns>"True" for pressed or "False" for not pressed</returns>
        Public Function GetButton(Index As Primitive) As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            If JoystickSB.js.GetButtons().ToArray()(Index) Then
                Return "True"
            End If
            Return "False"
        End Function
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the state of the POV hat with a given index
        ''' </summary>
        ''' <param name="Index">The number of the POV hat (starting with zero)</param>
        ''' <returns>"True" for pressed or "False" for not pressed</returns>
        Public Function GetPOV(Index As Primitive) As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Dim pov As Integer() = JoystickSB.js.GetPointOfViewControllers()
            Return pov(Index) / 100
        End Function
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the state of the slider with a given index
        ''' </summary>
        ''' <param name="Index">The number of the slider (starting with zero)</param>
        ''' <returns>0 to 65536</returns>
        Public Function GetSlider(Index As Primitive) As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Dim slider As Integer() = JoystickSB.js.GetSliders()
            Return slider(Index)
        End Function
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the state of the X axis
        ''' </summary>
        ''' <returns>0 to 65536</returns>
        Public Function GetX() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.X
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetXAcceleration() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.AccelerationX
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetXAngularAcceleration() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.AngularAccelerationX
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetXAngularVelocity() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.AngularVelocityX
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetXForce() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.ForceX
        End Function
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the state of the X axis rotation
        ''' </summary>
        ''' <returns>0 to 65536</returns>
        Public Function GetXRot() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.RotationX
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetXTorque() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.TorqueX
        End Function
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the state of the Y axis
        ''' </summary>
        ''' <returns>0 to 65536</returns>
        Public Function GetY() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.Y
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetYAcceleration() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.AccelerationY
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetYAngularAcceleration() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.AngularAccelerationY
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetYAngularVelocity() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.AngularVelocityY
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetYForce() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.ForceY
        End Function
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the state of the Y axis rotation
        ''' </summary>
        ''' <returns>0 to 65536</returns>
        Public Function GetYRot() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.RotationY
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetYTorque() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.TorqueY
        End Function
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the state of the Z axis
        ''' </summary>
        ''' <returns>0 to 65536</returns>
        Public Function GetZ() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.Z
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetZAcceleration() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.AccelerationZ
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetZAngularAcceleration() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.AngularAccelerationZ
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetZAngularVelocity() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.AngularVelocityZ
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetZForce() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.ForceZ
        End Function
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Gets the state of the Z axis rotation
        ''' </summary>
        ''' <returns>0 to 65536</returns>
        Public Function GetZRot() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.RotationZ
        End Function
    
        ' SB_Joystick.JoystickSB
        Public Function GetZTorque() As Primitive
            JoystickSB.js = JoystickSB.m_joystickDevice.GetCurrentState()
            Return JoystickSB.js.TorqueZ
        End Function
    
        ' SB_Joystick.JoystickSB
        Private Sub SetAxisRange()
            Dim directInputList As List(Of DeviceInstance) = New List(Of DeviceInstance)()
            Dim directInput As DirectInput = New DirectInput()
            directInputList.AddRange(directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            Dim m_joystickDevice As Joystick = New Joystick(directInput, directInputList(0).InstanceGuid)
            m_joystickDevice.Acquire()
            For Each deviceObject As DeviceObjectInstance In m_joystickDevice.GetObjects()
                If (deviceObject.ObjectType And ObjectDeviceType.Axis) <> ObjectDeviceType.All Then
                    m_joystickDevice.GetObjectPropertiesById(CInt(deviceObject.ObjectType)).SetRange(-1000, 1000)
                End If
            Next
        End Sub
    
        ' SB_Joystick.JoystickSB
        ''' <summary>
        ''' Unacquire the first joystick. This must be done after polling is over.
        ''' </summary>
        Public Sub Unacquire()
            Dim directInputList As List(Of DeviceInstance) = New List(Of DeviceInstance)()
            Dim directInput As DirectInput = New DirectInput()
            directInputList.AddRange(directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            Dim m_joystickDevice As Joystick = New Joystick(directInput, directInputList(0).InstanceGuid)
            m_joystickDevice.Acquire()
            m_joystickDevice.Unacquire()
        End Sub
    
    End Module
    


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Saturday, November 21, 2015 5:12 AM
    Answerer
  • Assuming you can get it to compile I would check the following, most of which you have probably done, but this is the list of what I know.

    0] Use the ILSpy File=>Save Code to extract a project to save it somewhere in new folder

    1] Reference SmallBasicLibrary.dll (version 1.2)

    2] Target Configuration Release Any CPU

    3] Target Framework .Net 4.5

    4] Install and reference (SlimDX.dll) SlimDX version 4.0, not 2.0

    5] Generate xml for intellisense

    If all else fails, then I would uninstall SB 1.2, install SB 1.0 and do the whole procedure using SlimDX 2.0, .Net 3.5 etc to check it can be done, then migrate back to SB 1.2 and upgrate the working solution.

    PS

    It worked fine for me first time, only change to above is that the intellisense xml isn't reproduced (not present in ILSpy generated project), but wecan just use the original. I guess your issue is just the SlimDX version.

    Any trouble and I can pass the dll I created.

    PPS

    Once SlimDX is installed you don't need to put its dll in SB/lib

    • Edited by litdev Saturday, November 21, 2015 11:29 AM
    Saturday, November 21, 2015 9:49 AM
  • Okay! If you got it working, would you mind posting it here? I'll keep trying though for educational purposes.

    Thanks!


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Saturday, November 21, 2015 4:55 PM
    Answerer
  • OK, here it is (download SB Joystick for SB 1.2), SlimDX for .Net 4.0 needs to be installed as well.

    Saturday, November 21, 2015 5:07 PM
  • Ok thank you for your help but it still doesn't work, maybe I am doing something wrong.

    I re-installed small basic 1.2, re installed EV3 basic, installed SlimDX for .net 4.0 and then copied the files from your archive in the Lib folder in the small basic files, it still doesn't work, maybe I did something wrong can you tell me ?

    I am sorry I am not really comfortable with all of this.

    Saturday, November 21, 2015 11:16 PM
  • I don't have EV3 but I do have an old joystick.

    My testing was only as far as connecting the joystick by USB, then running the SB program:

    TextWindow.WriteLine(JoystickForSmallBasic.AxesCount)

    And getting back an answer, in my case 4.

    Suggest perhaps you temporarily remove everything from lib folder apart from SB Joystick dll and xml and try my test with a simple joystick.

    I also tried by re-downloading the files I uploaded so I think they are good.

    Oh, one last thing - perhaps the downloaded dll needs to be unblocked - sometimes Windows is rightly protective of downloaded dlls - see description of what to do extracted from here, in your case it is the SB Joystick.dll not LitDev.dll.

    If the extension commands fail to appear in Small Basic (type LD and no options appear) then you may need to unblock the downloaded dll.  Right click LitDev.dll and select Properties and clear the block if present.  If it fails to unblock, then copy LitDev.dll to a folder where you have write access (e.g. Documents), unblock it there and then move back to the Small Basic lib folder.  Alternatively, unblock the downloaded zip file before unzipping the content.

    Saturday, November 21, 2015 11:42 PM
  • Yeah it was that, the DLL was blocked.

    Thank you very much dude, you're like my hero, I would actually pay you a pint if I were able to.

    lets start coding my damn robot then.

    all hail the great IT guys on internet.

    Sunday, November 22, 2015 12:24 AM
  • Glad its all working!

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Sunday, November 22, 2015 3:15 AM
    Answerer
  • hello sorry to disturb again,

    It seems to work fine but I have troubles with using the buttons of my controller.

    I use an Xbox 360 Controller and I am trying to use the A, B, X, Y buttons to do stuff with my robot but I don't have the information  while the button is being pushed with "JoystickForSmallBasicAdvanced.GetButton()".

    Here is the part of my code that uses this command, can you tell me what's wrong ? (if there's something wrong)

     While JoystickForSmallBasicAdvanced.GetButton(0) = "true"
        Motor.Start("C",15)
      EndWhile
      
      While JoystickForSmallBasicAdvanced.GetButton(3) = "true"
        Motor.Start("C",15)
      EndWhile
      
      While JoystickForSmallBasicAdvanced.GetButton(0) = "false" And JoystickForSmallBasicAdvanced.GetButton(0) = "false"
        Motor.Start("C",0)
      EndWhile

    thank you for your help again.

    Sunday, November 22, 2015 2:49 PM
  • Each While does its stuff while true, then moves on the the next statement.

    Pleasetest this code works when you press buttons.

    The logic is to keep looping for ever (a game loop with a small 20ms delay).  In each loop we get the state of all buttons, then do something based on their state before rerunning the loop and checking again.

    This may not be what you want to do but will test the controller buttons anf maybe give a clue why your code isn't doing what you want.

    JoystickForSmallBasicAdvanced.Acquire()
    GraphicsWindow.Show()
    
    While ("True")
      GetButtons()
      UpdateDisplay()
      Program.Delay(20)
    EndWhile
    
    Sub GetButtons
      For i = 1 To JoystickForSmallBasicAdvanced.ButtonCount
        buttonState[i] = JoystickForSmallBasicAdvanced.GetButton(i-1) 'These seem to be indexed from 0
      EndFor
    EndSub
    
    Sub UpdateDisplay
      For i = 1 To JoystickForSmallBasicAdvanced.ButtonCount
        If (buttonState[i]) Then
          GraphicsWindow.BrushColor = "Green"
        Else
          GraphicsWindow.BrushColor = "Red"
        EndIf
        GraphicsWindow.FillRectangle(22*i,20,20,20)
      EndFor
    EndSUb


    • Edited by litdev Sunday, November 22, 2015 3:59 PM Button indexing fromm 0
    Sunday, November 22, 2015 3:42 PM
  • Hum I detected the problem, I think my code doesn't work because I have two loops,
    I have one loop to control the movements of the robot, and another loop to use the buttons to do other actions. 

    I've tried to put everything in the same loop but it didn't work, here is my code, you can see the program you gave me earlier which works perfectly on its own.

    could you help me please ?

    '/////Command program/////
    
    
    '-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    JoystickForSmallBasicAdvanced.Acquire()
    
    '-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Start:
    Move()
    
      '//Control of the chasis//
    '-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      While ("true")
        While JoystickForSmallBasicAdvanced.GetY()>40000 And JoystickForSmallBasicAdvanced.GetX()>20000 And JoystickForSmallBasicAdvanced.GetX()<38301 'Rvancer
          Motor.StartSync("AB", 90, 90)
        EndWhile
        
        While JoystickForSmallBasicAdvanced.GetY()<25534 And JoystickForSmallBasicAdvanced.GetX()>20000 And JoystickForSmallBasicAdvanced.GetX()<38301 'Reculer
          Motor.StartSync("AB", -90, -90)
        EndWhile
        
        While JoystickForSmallBasicAdvanced.GetX()>40000 And JoystickForSmallBasicAdvanced.GetY()>20000 And JoystickForSmallBasicAdvanced.GetY()<38301 'Rotation à droite
          Motor.StartSync("AB", 90, -90)
        EndWhile
        
        While JoystickForSmallBasicAdvanced.GetX()<25534 And JoystickForSmallBasicAdvanced.GetY()>20000 And JoystickForSmallBasicAdvanced.GetY()<38301 'Rotation à gauche
          Motor.StartSync("AB", -90, 90)
        EndWhile
        
        While JoystickForSmallBasicAdvanced.GetX()<40000 And JoystickForSmallBasicAdvanced.GetX()>25534 And JoystickForSmallBasicAdvanced.GetY()<40000 And JoystickForSmallBasicAdvanced.GetY()>25534 'Mise à l'arrêt
          Motor.StartSync("AB", 0, 0)
        EndWhile
      EndWhile
    
      //Commands with buttons//
    '-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      GraphicsWindow.Show()
    
      While ("True")
        GetButtons()
        UpdateDisplay()
        Program.Delay(20)
        EndWhile
    
      Sub GetButtons
        For i = 1 To JoystickForSmallBasicAdvanced.ButtonCount
          buttonState[i] = JoystickForSmallBasicAdvanced.GetButton(i-1)
        EndFor
      EndSub
    
      Sub UpdateDisplay
        For i = 1 To JoystickForSmallBasicAdvanced.ButtonCount
          If (buttonState[i]) Then
            GraphicsWindow.BrushColor = "Green"
          Else
            GraphicsWindow.BrushColor = "Red"
          EndIf
          GraphicsWindow.FillRectangle(22*i,20,20,20)
        EndFor
      EndSUb
      
    '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    Goto Start
    thank you again.



    • Edited by tyrionas Monday, November 23, 2015 6:18 PM modification of the program
    Monday, November 23, 2015 6:15 PM
  • I think you are confusing what a While loop does.  You have to really understand while, for and if else endif properly before going forward.

    I suggest you start with a simple test program - perhaps start with the program I gave and slowly extend and read up on While.  Don't try to do it all in one go, forget about motors just now.

    Try some small changes and test that does exactly what you expect - put plenty of TextWindow.WriteLine statements in to check.

    Read through your code and imagine you are the computer reading each instructon and consider what path you would take.

    • Edited by litdev Friday, December 11, 2015 9:24 PM
    Monday, November 23, 2015 8:03 PM
  • Is this extension compiled for 1.2?

    Thanks!


    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Thursday, December 10, 2015 11:04 PM
  • Yes it it was decompiled and recompiled for V1.2 hosted temporarily at download SB Joystick for SB 1.2.

    PS forum does'nt seem to be updating new posts?

    • Edited by litdev Friday, December 11, 2015 9:23 PM
    Friday, December 11, 2015 9:21 PM