convert arduino code to matlab code

1 vue (au cours des 30 derniers jours)
rishabh vachhani
rishabh vachhani le 13 Nov 2019
Commenté : Walter Roberson le 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 commentaire
Walter Roberson
Walter Roberson le 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.

Connectez-vous pour commenter.

Réponses (1)

Arpit Bhatia
Arpit Bhatia le 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.

Catégories

En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by