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 //Warning light
I need help translating an Arduino code to LabVIEW form. Please note that I'm using a Arduino ATMEGA 2560.
The code is:
#include
//Warning light LED(s) const int ledPin1 = 51; const int ledPin2 = 53;
#include
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?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started