B4R Question Battlestar galactica cylon scanner - Arduino c to B4R

Discussion in 'B4R Questions' started by h725, Feb 9, 2019.

  1. h725

    h725 Member Licensed User

    Hello I am working on a battlestar galactica cylon scanner and have found
    the following snippet:

    Code:
    void setup() {
      // put your setup code here, 
    to run once:
    for (int pin= 2; pin <9; pin++) {
      pinMode(pin,OUTPUT);
    }
    }

    void loop() {
      // put your main code here, to run repeatedly:
      int a = 2;
    int t1 =35;
    int t2 = 1000;

    if (a=1){
    for (int i = 2; i<9;i++){
      digitalWrite(i,HIGH);
      delay(t1);
       digitalWrite(i+1,HIGH);
      delay(t1);
       digitalWrite(i+2,HIGH);
      delay(t1);
       digitalWrite(i,LOW);
    //  delay(t1);
       digitalWrite(i+1,LOW);
    }
    for (int i = 8; i>1;i--){
      digitalWrite(i,HIGH);
      delay(t1);
      digitalWrite(i-1,HIGH);
      delay(t1);
       digitalWrite(i-2,HIGH);
      delay(t1);
       digitalWrite(i,LOW);
      delay(t1);
       digitalWrite(i-1,LOW);
    }
    }
    }
    I would like to understand how to translate this code to B4R. I looked at the
    LED sample snippet and found out, that every LED has to be initialized first.
    Can somebody give me an idea what is the best way to translate the shown
    code to B4R?

    Thank you very much!
    h725
     
  2. Cableguy

    Cableguy Expert Licensed User

    Create a for/next loop with step +1 and when at the last step set the step to -1
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Start with:
    Code:
    Sub Process_Globals
       
    Public Serial1 As Serial
       
    Dim pins(11As Pin
    End Sub

    Private Sub AppStart
       Serial1.Initialize(
    115200)
       
    Log("AppStart")
       
    For i = 1 To 10
           pins(i).Initialize(i, pins(i).MODE_OUTPUT)
       
    Next
       
    Dim t1 As Int = 35
       
    For i = 2 To 8
           pins(i).DigitalWrite(
    True)
           Delay(t1)
           pins(i + 
    1).DigitalWrite(True)
           Delay(t1)
           pins(i + 
    2).DigitalWrite(True)
           Delay(t1)
           pins(i).DigitalWrite(
    False)
           pins(i + 
    1).DigitalWrite(False)
       
    Next
       
    For i = 8 To 2 Step - 1
           
    '...
       Next
    End Sub
    Note that this code writes to pin #1 which is the serial port pin. It doesn't look correct.
     
  4. thetahsk

    thetahsk Member Licensed User

  5. h725

    h725 Member Licensed User

    Great - as always.
    Thank you for your help!
     
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