Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help translating an Arduino code to LabVIEW form. Please note that I\'m u

ID: 3874537 • Letter: I

Question

I need help translating an Arduino code to LabVIEW form. Please note that I'm using a Arduino ATMEGA 2560.

The code is:


#include <EEPROM.h>

//Warning light LED(s)
const int ledPin1 = 51;   
const int ledPin2 = 53;

#include <Servo.h>     //Servo library to activate gate
int servoPin1 = 9;     //Connected to first gate
Servo myServo1;        //Name of first gate
int servoPin2 = 8;       //Connected to second gate
Servo myServo2;        //Name of second gate
int gate = 0;

int buzzer = 52;

void setup()
{
    //IR Sensor Detector1
    pinMode(A0, INPUT);
    pinMode(A1, OUTPUT);
    pinMode(A2, OUTPUT);
    digitalWrite(A2, HIGH);
    digitalWrite(A1, LOW);

    //IR Sensor Detector2
    pinMode(A3, INPUT);
    pinMode(A4, OUTPUT);
    pinMode(A5, OUTPUT);
    digitalWrite(A5, HIGH);
    digitalWrite(A4, LOW);

    //IR Sensor Detector3
    pinMode(A6, INPUT);
    pinMode(A7, OUTPUT);
    pinMode(A8, OUTPUT);
    digitalWrite(A8, HIGH);
    digitalWrite(A7, LOW);

    //IR Sensor Detector2
    pinMode(A9, INPUT);
    pinMode(A10, OUTPUT);
    pinMode(A11, OUTPUT);
    digitalWrite(A11, HIGH);
    digitalWrite(A10, LOW);

    //Arduino configuration
    //Serial.begin(9600);

    //Warning light definition
    pinMode(ledPin1, OUTPUT);
    pinMode(ledPin2, OUTPUT);

    pinMode(buzzer, OUTPUT);

    //Servo control definition
    myServo1.attach(servoPin1);
    myServo2.attach(servoPin2);

    EEPROM.write(0, 0);
    EEPROM.write(1, 0);
}

void loop()
{  
    //Read IR sensor dector(s)
    //Serial.println(analogRead(A0));
    //Serial.println(analogRead(A3));
    //Serial.println(analogRead(A6));
    //Serial.println(analogRead(A9));
if(EEPROM.read(1) == 0 || EEPROM.read(0) == 0)
{
    //When the train is not detected the railroad gate circuit will turn off
    while(analogRead(A0) < 500)
    {
        if(analogRead(A3) < 500)
        {

            if(EEPROM.read(1)!=1)
            {
                EEPROM.write(1, 1);
            }
            if(EEPROM.read(0)!=1)
            {
                EEPROM.write(0, 1);
            }
       
            delay(100);     
         }
    }

    while(analogRead(A6) < 500)
    {
        if(analogRead(A9) < 500)
        {

            if(EEPROM.read(1)!=1)
            {
                EEPROM.write(1, 1);
            }
            if(EEPROM.read(0)!=1)
            {
                EEPROM.write(0, 1);
            }
       
            delay(100);     
         }
    }   
}

if(EEPROM.read(1)==1 || EEPROM.read(0)==0)
{
    while(analogRead(A3) < 500)
    {
        if(analogRead(A0) < 500)
        {
            if(EEPROM.read(1)!=0)
            {
                 EEPROM.write(1, 0);
            }
            if(EEPROM.read(0)!=1)
            {
                 EEPROM.write(0, 1);
            }
           
            delay(100);
        }
    }

    while(analogRead(A9) < 500)
    {
        if(analogRead(A6) < 500)
        {
            if(EEPROM.read(1)!=0)
            {
                 EEPROM.write(1, 0);
            }
            if(EEPROM.read(0)!=1)
            {
                 EEPROM.write(0, 1);
            }
           
            delay(100);
        }
    }
}  

    //Gate open
    if(EEPROM.read(1) == 1)
    {
        if(gate != 90)
        {
            for (gate = 0; gate < 90; gate += 1)
            {
                myServo1.write(gate);
                myServo2.write(gate);
               
                tone(52,4000,100);               //The buzzer will sound from Pin8, play at a 4000 frequency rate, and the note will play at 150ms long
                delay(20);  

                digitalWrite(ledPin1, HIGH);    //This LED will turn on
                digitalWrite(ledPin2, LOW);     //This LED will turn off
                delay(20);                     //150ms wait time before the program moves to the next line of code

                digitalWrite(ledPin1, LOW);     //This LED will turn off
                digitalWrite(ledPin2, HIGH);    //This LED will turn on
                delay(20);
            }
        }

        //Serial.println("Gate Opened");
        digitalWrite(buzzer, LOW);
        digitalWrite(ledPin1, LOW);   
        digitalWrite(ledPin2, LOW);
        if (EEPROM.read(0)!=0)
        {
          EEPROM.write(0, 0); /*Serial.println("OK");*/
        }
    }

    if (EEPROM.read(1)==0)
    {    
        //Gate close
        if (gate != 0)
        {
            for (gate = 90; gate > 0; gate -= 1)
            {
                myServo1.write(gate);
                myServo2.write(gate);
                tone(52,4000,100);               //The buzzer will sound from Pin8, play at a 4000 frequency rate, and the note will play at 150ms long
                delay(20);  
               
                digitalWrite(ledPin1, HIGH);    //This LED will turn on
                digitalWrite(ledPin2, LOW);     //This LED will turn off
                delay(20);                     //150ms wait time before the program moves to the next line of code

                digitalWrite(ledPin1, LOW);     //This LED will turn off
                digitalWrite(ledPin2, HIGH);    //This LED will turn on
                delay(20);
            }
        }
   
        //Serial.println("Gate Closed");   
        if(EEPROM.read(0)!=0)
        {
            EEPROM.write(0, 0);
            Serial.println("OK");
        }
    }
}

How do you translate this code into the block diagram of LabVIEW using Arduino?

Explanation / Answer

Put simply, the LabVIEW Interface for Arduino sends data packets from LabVIEW to the Arduino. The Arduino processes these packets and sends return packets. Return packets are parsed by LabVIEW to provide useful information to the end user. Each packet is 15 bytes by default and contains a header, a command byte, data bytes, and a checksum. The packet length can be changed to suit specific applications by modifying the firmware and specifying the packet size to the Init VI in LabVIEW (Most users will not need to do this). The LIFA firmware on the Arduino processes the packets by ensuring no data has been corrupted during transmission, then checks the command byte and execute instructions with the given data bytes based on the command byte.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote