MATLAB Answers

convert arduino code to matlab code

조회 수: 2(최근 30일)
rishabh vachhani
rishabh vachhani 13 Nov 2019
댓글: Walter Roberson 30 Oct 2020
#include<LiquidCrystal.h>
#include<Servo.h>
LiquidCrystal lcd(2,3,4,5,6,7);
Servo myServo;
const int in=8;
const int out=9;
const int redledPin=11;
const int greenledPin=12;
int count=13;
void setup()
{
Serial.begin(9600);
myServo.attach(10);
lcd.begin(16,2);
lcd.print("welcome");
delay(3000);
pinMode(in,INPUT);
pinMode(out,INPUT);
pinMode(redledPin,OUTPUT);
pinMode(greenledPin,OUTPUT);
lcd.clear();
lcd.print("parking available");
lcd.setCursor(0,1);
lcd.print(count);
}
void loop()
{
int in_value= digitalRead(in);
int out_value=digitalRead(out);
if(in_value==LOW && count>0)
{
count--;
lcd.clear();
lcd.print("welcome");
lcd.clear();
lcd.print("parking available");
lcd.setCursor(0,1);
lcd.print(count);
digitalWrite(redledPin,LOW);
digitalWrite(greenledPin,HIGH);
myServo.write(180);
delay(2000);
myServo.write(0);
}
else{
lcd.clear();
lcd.print("welcome");
digitalWrite(greenledPin,LOW);
digitalWrite(redledPin,HIGH);
}
if((out_value=LOW)&&(count<13));
{
count++;
lcd.clear();
lcd.print("welcome");
lcd.clear();
lcd.print("parking available");
lcd.setCursor(0,1);
lcd.print(count);
myServo.write(180);
digitalWrite(redledPin,LOW);
digitalWrite(greenledPin,HIGH);
delay(2000);
myServo.write(0);
}
if else
{
lcd.clear();
lcd.print("welcome");
digitalWrite(greenledPin,LOW);
digitalWrite(redledPin,HIGH);
}
if(count==0)
{
lcd.clear();
lcd.print("please come later");
lcd.setCursor(0,1);
lcd.print(count);
delay(2000);
}
}
  댓글 수: 1
Walter Roberson
Walter Roberson 30 Oct 2020
MATLAB does not have any servo control itself, or any LCD screens. It has some toolboxes that can talk to instruments, or talk to data acquisition hardware, but its only direct ability to manipulate digital lines is some obscure functions that can do some changes to digital lines on (true) parallel ports.
It is not obvious what the MATLAB code would be intended to do?
If the idea would just be to convert to having the host use arduino() to communicate with the device instead of having C code compiled and transmittedto the arduino, then Yes that could be done, but the maximum effective data rate would be able 5 hz.

댓글을 달려면 로그인하십시오.

답변(1개)

Arpit Bhatia
Arpit Bhatia 30 Oct 2020
Hi Rishabh,
To convert Arduino code to MATLAB, you can use the MATLAB Support Package for Arduino Hardware. To get started, please have a look at the link below.
Alternatively, since Arduino uses C, the following link on how to call C files from within MATLAB may help.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by