convert arduino code to matlab code
조회 수: 1 (최근 30일)
이전 댓글 표시
#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
2020년 10월 30일
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
2020년 10월 30일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!