Menu

How to Program Arduino UNO R3 With GCBASIC

2015-01-28
2023-06-30
<< < 1 2 3 4 (Page 4 of 4)
  • Keith

    Keith - 2022-09-19

    Thanks Mike. I'm using Mach 3 (Paid Version) for most of my CNC Needs but I want to use this on on a mini-Surface Grinder I have built.
    I must confess this Arduino thing is a bit of a beast, it is a bit like my little Jack Russel Terrier - Only does what you want him to do when he thinks fit. If he had two fingers I know what he would do sometimes. I'll take a look at this GRBL stuff shortly. Thanks again.

     
  • Keith

    Keith - 2022-09-20

    I want to use Case Select to step through 5 options but I'm failing miserably. What I have so far after 3 hours is:-

    BTTNPUSH = READAD10(AN0)
    ButtonRight = BTTNPUSH < 50
    ButtonUp = BTTNPUSH >60 and BTTNPUSH < 200
    ButtonDown = BTTNPUSH >200 and BTTNPUSH < 400
    ButtonLeft = BTTNPUSH >400 and BTTNPUSH < 600
    ButtonSelect = BTTNPUSH >600 and BTTNPUSH < 800

    Select Case ButtonDown = 1
    Case 0
    CLS
    PRINT "Option 1 "
    ; Print ButtonRight

     Case 1
      CLS
      PRINT "Option 2"
     Case 2
      CLS
      PRINT "Option 3"
     Case 3
      CLS
      PRINT "Option 4"
    Case 4
      CLS
      PRINT "Option 5"
    

    End Select

    What I want to happen is everytime I hit Buttondown it advances through the options then resets back to the beginning.
    This is beginning to make one of my other hobbies "Recreational Chemistry" look appealing.

     
    • Anobium

      Anobium - 2022-09-21

      You need a state engine. This means for that you have a tracking variable.

      Set the variable and then increment each time then reset when a maximum value is met. There are many ways to do this but this is simple way to do it. ( Untested)

      Dim ButtonState as Byte
      ButtonState = 0
      
      
      Do 
          BTTNPUSH = READAD10(AN0)
          ButtonRight = BTTNPUSH < 50
          ButtonUp = BTTNPUSH >60 and BTTNPUSH < 200
          ButtonDown = BTTNPUSH >200 and BTTNPUSH < 400
          ButtonLeft = BTTNPUSH >400 and BTTNPUSH < 600
          ButtonSelect = BTTNPUSH >600 and BTTNPUSH < 800
      
          if ButtonDown = True Then
      
              Select Case ButtonState = 1
              Case 0
                  CLS
                  PRINT "Option 1 "
               Case 1
                    CLS
                    PRINT "Option 2"
               Case 2
                    CLS
                    PRINT "Option 3"
               Case 3
                    CLS
                    PRINT "Option 4"
              Case 4
                    CLS
                    PRINT "Option 5"
               Case Else
                   ButtonState = 0
               End Case
      
               'increment the state
               ButtonState++
      
      Loop   
      
       
  • Keith

    Keith - 2022-09-21

    Thank you so much once again Evann. This is crazy I know but I still cannot get it work as it should, for some apparent reason it needs an End If somewhere in response to the
    if ButtonDown = True Then
    condition. I have tried it in every conceivable position as I feel it is that which is preventing it from stepping through the case statements.
    I don't what it is but I don't seem to come across as many basic low level problems with Microchip devices ? This Arduino business is taking my programming skills back to scratch one.

     
  • Anobium

    Anobium - 2022-09-22

    I can help. :-)

    Post what you have.

     
  • Keith

    Keith - 2022-09-22

    Here is what I have so far. I changed the names of a couple of variables as the original ones clashed with what I had.

     
  • Anobium

    Anobium - 2022-09-22

    Line 28.. looks incorrect but this will not impact the CASE statement.

    This is the issue

    Line 79 Select Case SelectButton = 1 should read Select Case SelectButton

    The existing line 79 will operate the case then SelectButton is 1 and the only case will look for a value of 255 for the case.... But, Select Case SelectButton will do what you want.

     
  • stan cartwright

    stan cartwright - 2022-09-22

    Anobium. If instead of a pin for each button , this using just one a-d to read 5 buttons is cool?

     
    • Keith

      Keith - 2022-09-22

      Yes Stan but it is a real Pain in the Butt to get to work properly !

       
  • Keith

    Keith - 2022-09-22

    @ Anobium. Crying out loud, this is really getting to me but I'm not giving up just yet. Take a look at the video below, you won't believe what it is doing. The full code is also attached.

     
  • Keith

    Keith - 2022-09-22

    @ Anobium. Crying out loud, this is really getting to me but I'm not giving up just yet. Take a look at the video below, you won't believe what it is doing. The full code is also attached.

     

    Last edit: Keith 2022-09-22
  • Keith

    Keith - 2022-09-22

    Code as in above

     

    Last edit: Keith 2022-09-22
  • Keith

    Keith - 2022-09-22

    Video is too big to upload. I need to convert it on my other PC to show you what it is doing. Unless you can try it out on one of your UNO's as I have a feeling the CPU on this thing may be damaged.

    Some of the problems I'm having is beyond comprehension. GRRR !

     
  • Anobium

    Anobium - 2022-09-23

    Don't give up. I am out today. So, I have adapted the program to help isolate this issue.

    I have removed the ADC read and set a return value of 201. This will simulate the button press. I get the menus cycling thru the options 1 to 6. What do you get?

     
    • Anobium

      Anobium - 2022-09-23

      and, my hex to rule out your installation....

       
  • Keith

    Keith - 2022-09-23

    If I press and hold the down key the display cycles through all the options but it advances randomly on a single one shot of the down key. It's as if the down button needs a de-bounce routine.
    Secondly any instruction within the case options are ignored such as in "If ButtonSelect > 0 Then

    Case 0
    CLS
    PRINT "Option 1 "
    Locate 1,5
    If ButtonSelect > 0 Then
    Goto Test
    End if

     
  • stan cartwright

    stan cartwright - 2023-04-14

    You got competition. There's interpreted basic for these but they are so fast it doesn't need compiling. https://www.adafruit.com/product/4864

     
    • Anobium

      Anobium - 2023-04-14

      LOL.... does that BASIC do PIC? LOL

       
<< < 1 2 3 4 (Page 4 of 4)

Log in to post a comment.