rTrafficLight

Additional Open Source B4R Libraries.
rwblinn
Site Admin
Posts: 179
Joined: 07 Oct 2017, 12:16

rTrafficLight

Postby rwblinn » 08 Oct 2017, 19:17

rTrafficLight - Library to explore writing an own B4R library from scratch.
Developed in C++.

Library
• Controlling 3 LEDs Red-Yellow-Green
• Learn how to use Arduino Functions but also how to create a B4R library.

Wiring
LED = Arduino - Tested on an UNO
RED = D8
YELLOW = D9
GREEN = D10
GND = GND for all LEDs

Download Source Code with B4R Example
http://www.rwblinn.de/b4r/b4rhowto/examples/b4rhowtotrafficlight.zip
http://www.rwblinn.de/b4r/b4rhowto/examples/rtrafficlight.zip

ToDo
• Library is completed (unless bugs are reported)

Changelog
20170216 v1.0

B4R Example with all Functions

Code: Select all

Sub Process_Globals
  Public Serial1 As Serial
  Private tl As TrafficLight
End Sub

Private Sub AppStart
  Serial1.Initialize(115200)
  Delay(100)
  Log("AppStart")

  Log("Init the Traffic Light LEDs")
  'Pin mapping for the LEDs: D8 = Red, D9 = Yellow, D10 = Green
  tl.Initialize(8,9,10)

  Log("Library Version:")
  Log(tl.Version)

  Log("Set LED Red=off,Yellow=on,Green=on")
  tl.SetState(False,True,True)

  Log("Get the state for each of the LEDs as ArrayByte:")
  Dim b() As Byte = tl.GetState
  Log("Length:", b.Length,", State Red-Yellow-Green: ",b(0),"-",b(1),"-",b(2))
  Delay(5000)

  Log("Simulate a traffic light (rather simple)")
  tl.Simulate
  Delay(5000)

  Log("Turn LED Red on and log the state (0=off, 1=on)")
  tl.Red = True
  Log("State LED Red: ", tl.Red)

  Log("Turn all LEDs on")
  tl.TurnOn
  Delay(2000)

  Log("Turn all LEDs off")
  tl.TurnOff
End Sub

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest