B4R Tutorial Blink Example

Discussion in 'B4R Tutorials' started by Erel, Apr 11, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    A simple example that uses a Timer to change the state of pin 13 (this is the pin connected to the built-in led):
    Sub Process_Globals
    Public Serial1 As Serial
    Private Timer1 As Timer
    Private pin13 As Pin
    End Sub

    Private Sub AppStart
    13, pin13.MODE_OUTPUT)
    "Timer1_Tick"1000'1000ms = 1 second
       Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick
    Dim currentState As Boolean = pin13.DigitalRead
    Log("CurrentState: ", currentState)
    Dim NewState As Boolean = Not(currentState)
    Log("NewState: ", NewState)
    End Sub
  2. tufanv

    tufanv Expert Licensed User

    this is the b4r version of arduino's blink example right ?
  3. Erel

    Erel Administrator Staff Member Licensed User

    The functionality is the same. Unlike the blink example that is based on a loop with calls to Delay, the above code doesn't pause the execution thread. So the program can do many other things while it also toggles the led.
  4. Toley

    Toley Active Member Licensed User

    Do B4R have a delay(ms) function?
  5. Beja

    Beja Expert Licensed User

    The best bet is to use another timer and initialize it with the delay value you wish.. you can also modify that value at runtime
    for uses in other subs or anything else. just make sure to disable it after each use and only enable it when you need to use it.
  6. Erel

    Erel Administrator Staff Member Licensed User

    Serdar K., jcohedman and Cableguy like this.
  7. demasi

    demasi Active Member Licensed User

    I'm trying to run this BLINK example in my Arduino Mega 2560, but it doesn't load.
    I can load and rur normally with Arduino IDE with same model/port configurations.
    I'm using the most recent B4R.
    I got this error:

    2016-10-13 21 34 22.png
  8. Erel

    Erel Administrator Staff Member Licensed User

    demasi likes this.
  9. demasi

    demasi Active Member Licensed User

    It works ok now. Thank you!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice