Menu

Help with 'Button-press' syntax please

Help
Anonymous
2013-03-16
2013-05-30
  • Anonymous

    Anonymous - 2013-03-16

    Hi,
    In the GCBasic online tutorial there is the command 'DO'. There is some code to demonstrate
    how the command works. I'm inexpert in BASIC syntax as applied to micros and I couldnt make
    sense of the syntax.

    #define BUTTON PORTA.0   OK, so when the compiler sees 'BUTTON' it understands it as an I/O pin.

    then there is:  DO WHILE BUTTON pressed.

    After DO WHILE you put some 'condition'. That 'condition' is that the button is pressed, making
    the pin  either 0 or 1 ( depending on the wiring ). But the code doesnt say 0 or 1,
    it says: 'pressed'. But, AFAIK, there is no BASIC command called 'pressed', so how does the
    compiler know?
    Regards
    Bruce

     
  • lhatch

    lhatch - 2013-03-18

    Maybe like set LED on  and set LED off, the on and off are predefined in the program, so pressed might equate to 1?

    Just a guess, but there might be reserved word and a list somewhere.  Or it needs to be defined and the example are just to point you in the right direction.

    In the manual, this is what I fond for DO

    Do Until BUTTON = 1
        PulseOut LIGHT, 1 s
        Wait 1 s
    Loop

     
  • Anonymous

    Anonymous - 2013-03-18

    Hi,
    Thanks for the reply.
    I dont believe 'pressed' is a reserved word: I checked the help file and see nothing on there.
    It would make sense if there was a   #define,  pressed, 1, but there isnt.
    I was hoping somebody else on the forum would know or at least have seen that code and wondered the same as I did.
    But yours has been the only reply.

    Bruce

     
  • Hugh Considine

    Hugh Considine - 2013-03-19

    That looks like a rather old help article from about 2006 that is overdue for an update! There is a more up to date help file included with any more recent updates of the compiler, or with GCGB.

    PRESSED isn't a reserved word in the compiler, so you would need to define it like this:

    #define PRESSED 1

    If the pin is high when the button is pressed. If the pin is low when pressed, then you would define PRESSED as 0 instead.

    A lot of those early examples aren't actually complete, functional programs - they show you the syntax, but they are missing bits and pieces that would be needed to compile them. I've tried to address this recently, and you can also get a more up to date help file at http://gcbasic.sourceforge.net/newfiles/help/

     
  • lhatch

    lhatch - 2013-03-19

    I should have caught that.  I sometimes end up on the old one.  The key to the new one is   /newfiles/help.   I added it to my bookmarks.

    Either way, the samples are just to help with the single function as a lot of them will not run.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.