Dear Friends,
I have modified Erel's tutorial example of traffic light, but am getting strange error during compilation.
Using Arduino Uni as target board.
the code and error are as followspls note it is a partial code, some subs are yet to be coded!)
I have modified Erel's tutorial example of traffic light, but am getting strange error during compilation.
Using Arduino Uni as target board.
the code and error are as followspls note it is a partial code, some subs are yet to be coded!)
B4X:
Sub Process_Globals
Public Serial1 As Serial
Type State (A1 As Boolean, B1 As Boolean, A2 As Boolean,B2 As Boolean,A3 As Boolean, B3 As Boolean, A4 As Boolean, B4 As Boolean,Duration As UInt)
Private pinA1,pinB1,pinA2,pinB2,pinA3,pinB3,pinA4,pinB4 As Pin
Private States(16) As State
Private CurrentStateIndex As Int = 0
Dim pinN,pinS,pinE,pinW As Pin
End Sub
Private Sub AppStart
Serial1.Initialize(9600)
Log("AppStart")
pinA1.Initialize(2,pinA1.MODE_OUTPUT)
pinB1.Initialize(3,pinB1.MODE_OUTPUT)
pinA2.Initialize(4,pinA2.MODE_OUTPUT)
pinB2.Initialize(5,pinB2.MODE_OUTPUT)
pinA3.Initialize(6,pinA3.MODE_OUTPUT)
pinB3.Initialize(7,pinB3.MODE_OUTPUT)
pinA4.Initialize(8,pinA4.MODE_OUTPUT)
pinB4.Initialize(9,pinB4.MODE_OUTPUT)
pinN.Initialize(10,pinN.MODE_INPUT)
pinS.Initialize(11,pinN.MODE_INPUT)
pinE.Initialize(12,pinN.MODE_INPUT)
pinW.Initialize(13,pinN.MODE_INPUT)
pinN.AddListener("pinN_StateChanged")
pinS.AddListener("pinS_StateChanged")
pinE.AddListener("pinE_StateChanged")
pinW.AddListener("pinW_StateChanged")
'Reset the pins
For Each p As Pin In Array As Pin(pinA1,pinB1,pinA2,pinB2,pinA3,pinB3,pinA4,pinB4)
p.DigitalWrite(False)
Next
SetState(States(0), False, False, False,True,False,True,False,True, 20000)
SetState(States(1), True, False, False,True,False,True,False,True ,5000)
SetState(States(2), False, True, False,True,False,True,False,True ,10000)
SetState(States(3), True, True, False,True,False,True,False,True ,20000)
SetState(States(4), False, True, False,False,False,True,False,True ,20000)
SetState(States(5), False, True, True,False,False,True,False,True ,5000)
SetState(States(6), False, True, False,True,False,True,False,True ,10000)
SetState(States(7), False, True, True,True,False,True,False,True ,20000)
SetState(States(8), False, True, False,True,False,False,False,True ,20000)
SetState(States(9), False, True, False,True,True,False,False,True ,5000)
SetState(States(10), False, True, False,True,False,True,False,True ,10000)
SetState(States(11), False, True, False,True,True,True,False,True ,20000)
SetState(States(12), False, True, False,True,False,True,False,False ,20000)
SetState(States(13), False, True, False,True,False,True,True,False ,5000)
SetState(States(14), False, True, False,True,False,True,False,True ,10000)
SetState(States(15), False, True, False,True,False,True,True,True ,20000)
RunState(0)
End Sub
Private Sub SetState(s As State, A1Value As Boolean, B1Value As Boolean, A2Value As Boolean, B2Value As Boolean,A3Value As Boolean,B3Value As Boolean, A4Value As Boolean, B4Value As Boolean, duration As UInt)
s.A1 = A1Value
s.B1=B1Value
s.A2=A2Value
s.B2=B2Value
s.A3=A3Value
s.B3=B3Value
s.A4=A4Value
s.B4=B4Value
s.Duration = duration
End Sub
Private Sub RunState(unused As Byte)
Log("CurrentStateIndex: ", CurrentStateIndex)
Dim s As State = States(CurrentStateIndex)
pinA1.DigitalWrite(s.A1)
pinB1.DigitalWrite(s.B1)
pinA2.DigitalWrite(s.A2)
pinB2.DigitalWrite(s.B2)
pinA3.DigitalWrite(s.A3)
pinB3.DigitalWrite(s.B3)
pinA4.DigitalWrite(s.A4)
pinB4.DigitalWrite(s.B4)
CurrentStateIndex = (CurrentStateIndex + 1) Mod States.Length
'switch to the next state after the current state duration.
CallSubPlus("RunState", s.Duration, 0)
End Sub
Sub pinN_StateChanged
If pinN.DigitalRead=True Then
Dim s As State = States(CurrentStateIndex)
CurrentStateIndex=0
CallSubPlus("RunState", s.Duration, 0)
End If
End Sub
Sub pinS_StateChanged
End Sub
Sub pinE_StateChanged
End Sub
Sub pinW_StateChanged
End Sub
B4X:
B4R version: 1.80
Parsing code. (0.01s)
Compiling code. (0.01s)
Building project (0.01s)
Compiling & deploying Ino project (Arduino/Genuino Uno - COM2) Error
In file included from C:\Users\RAJESH\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.18\cores\arduino/Arduino.h:32:0,
from sketch\B4RDefines.h:8,
from sketch\B4RArduino.cpp:1:
C:\Users\RAJESH\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.18\cores\arduino/binary.h:31:12: error: expected unqualified-id before numeric constant
#define B1 1
^
sketch\b4r_main.h:37:6: note: in expansion of macro 'B1'
bool B1;
^
exit status 1
Error compiling for board Arduino/Genuino Uno.