B4R Question Addlooper not work..

Discussion in 'B4R Questions' started by takhmin77, Jun 27, 2018.

  1. takhmin77

    takhmin77 Member

    hi
    i want to show numbers on 8 digit 7 segment that use 74hc595 chip
    when i set single value , looper work fine and show number correct
    but in for..next loop , its not work and wait 10 second , and just show last number on 7 segment
    i want when u is 1 , show 1 on 7 segment ... to end..

    the looper wait to ending for..next loop , then work and just display 10 on 7 segment
    my code :
    Code:
    Sub Process_Globals


        
    Dim bc As ByteConverter
        
    Public Serial1 As Serial

        
    Private pos() As Byte = Array As Byte (0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01' 0 to 7
        Private num()  As Byte = Array As Byte(0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90,0X7F,0XFF,0XBF' 0 to 9 . -

        
    Private pos_data As Byte
        
    Private num_data As Byte
        
    Private adad As ULong

        
    Private lPin, cPin, dPin As Pin

    'for inline function
        Private LATCH As Int = 4
        
    Private CLOCK As Int = 7
        
    Private DATA  As Int = 8


    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
                     
        lPin.Initialize(
    4,lPin.MODE_OUTPUT)
        cPin.Initialize(
    7,cPin.MODE_OUTPUT)
        dPin.Initialize(
    8, dPin.MODE_OUTPUT)

        AddLooper(
    "Loopey")
        
    For u = 1 To 10
        adad = u
        Delay(
    1000)
        
    Next

    End Sub

    Sub Loopey
        
    Dim jj As String = NumberFormat(adad,0,0)
        
    Dim cntr As Byte = 0
        
    For y = jj.Length -1 To 0 Step -1
            
    Dim ha As String =bc.StringFromBytes( bc.SubString2(jj,cntr,cntr+1))
            
    Dim aa As Int=ha
            Shiftout( num(aa),pos(y) )
            cntr=cntr+
    1
        
    Next
    End Sub

    Sub Shiftout (data_to_show As Byte , position As Byte)
        pos_data=position
        num_data=data_to_show
        RunNative(
    "shiftout_inline"Null)
    End Sub


    #If C
     void shiftout_inline(B4R::Object* o) {
     digitalWrite(b4r_main::_latch, LOW);
      shiftOut(b4r_main::_data, b4r_main::_clock, MSBFIRST, b4r_main::_pos_data);
     shiftOut(b4r_main::_data, b4r_main::_clock, MSBFIRST, b4r_main::_num_data);
      digitalWrite(b4r_main::_latch, HIGH);
      }
    #End If
     
  2. tigrot

    tigrot Well-Known Member Licensed User

    I don't think this is correct. I'd write a timer sub to perform every n milliseconds. Forget loopers.
     
  3. takhmin77

    takhmin77 Member

    hi
    i cange my code and add timer , but problem not solevd
    Code:
    Sub Timer1_Tick
        
    Dim jj As String = NumberFormat(adad,0,2)
        
    Dim cntr As Byte = 0
        
    For y = jj.Length -1 To 0 Step -1
            
    Dim ha As String =bc.StringFromBytes( bc.SubString2(jj,cntr,cntr+1))
            
    Dim aa As Int=ha
            
    If ha="." Then aa=10
            
    If ha="-" Then aa=11
            Shiftout( num(aa),pos(y))
            cntr=cntr+
    1
        
    Next
    End Sub
     
  4. tigrot

    tigrot Well-Known Member Licensed User

    I think you don't pass the correct values to the C routine. Define a B4R variable for each parameters and access from inline C. You can pass only one parameter in B4R. I have not access to my code since I'm out.
    Mauro
     
    Johan Hormaza likes this.
  5. takhmin77

    takhmin77 Member

    hi
    it work out of the for..next loop
    out of the loop , when i change adad value , the inline c code , recive correct value , but in loop , parameter not pass to inline c code until ending loop
    For u = 1 To 10
    adad = u
    Delay(1000)
    Next
     
  6. tigrot

    tigrot Well-Known Member Licensed User

    In loop i don't see any code to show values. You loop and no action is performed, since the processor is never able to perform anything else then the loop itself. Timer is not executed in loop.
     
  7. takhmin77

    takhmin77 Member

    thanks
     
    tigrot likes this.
Loading...
  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