Dear friends,
I am trying to count the number of state changes (positive going edges) on one of the pins of Wemos using addlistner method. For testing purposes, I am using another pin of Wemos to generate the pulses , naturally shorting both the pins. Expecting that one timer generates the pulses another timer displays the count. But this does not seem to work. My test code is as follows:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Note that the timers are initialised such that the generating timer is faster than the displaying timer.
			
			I am trying to count the number of state changes (positive going edges) on one of the pins of Wemos using addlistner method. For testing purposes, I am using another pin of Wemos to generate the pulses , naturally shorting both the pins. Expecting that one timer generates the pulses another timer displays the count. But this does not seem to work. My test code is as follows:
			
				B4X:
			
		
		
		Sub Process_Globals
   Public Serial1 As Serial
   Private ip,op As Pin
   Private wemos As D1Pins
   Dim count As Int
   Dim timer1 As Timer
   Dim timer2 As Timer
End Sub
Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   ip.Initialize (wemos.D5, ip.MODE_INPUT)
    op.Initialize (wemos.D6, op.MODE_OUTPUT)
   ip.AddListener("Change_state")
   timer1.Initialize("timer1_tick",2000)
   timer2.Initialize("timer2_Tick",1000)
timer1.Enabled=True
timer2.Enabled=True
End Sub
Sub timer1_tick
   
    Log(count)
    count=0
End Sub
Sub timer2_tick
    op.DigitalWrite(True)
    Delay(100)
    op.DigitalWrite(False)
    Delay(100)
End Sub
Sub Change_state (State As Boolean)
       
  Select Case State
      Case True
        Log("state: Detected")
        count=count+1   
    Case False
        Log("state: Not Detected")
  End Select
End Sub
	Note that the timers are initialised such that the generating timer is faster than the displaying timer.