change arduino code into matlab code

5 ビュー (過去 30 日間)
JI-Min Jeong
JI-Min Jeong 2017 年 6 月 4 日
回答済み: Sid Jhaveri 2017 年 6 月 6 日
i want to use servo motor and ultrasonic sensor in matlab. please let me know how to change arduino code into matlab code.
#include <Servo.h>
Servo myservo;
long duration;
long distance1 = 100;
long distance2 = 100;
void setup()
{
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(2, INPUT);
pinMode(13, OUTPUT);
myservo.attach(4);
myservo.write(150);
}
void loop()
{
digitalWrite(3, HIGH);
delayMicroseconds(10);
digitalWrite(3, LOW);
duration = pulseIn(2, HIGH);
distance1 = duration / 29 / 2;
// Serial.print(distance1);
// Serial.println(" cm");
if (distance1 < 30)
{
digitalWrite(13, HIGH);
if (abs(distance1 - distance2) < 30) myservo.write(150);
}
else
{
digitalWrite(13, LOW);
if (abs(distance1 - distance2) < 30) myservo.write(30);
}
distance2 = distance1;
delay(100);
}
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 6 月 4 日
編集済み: Walter Roberson 2017 年 6 月 4 日
How would you interface the sensors and servo to MATLAB? Would you connect them to an analog/digital convertor module such as National Instruments?
Or is the idea that you would continue to use arduino, but you would have MATLAB tell arduino what to do?

サインインしてコメントする。

回答 (1 件)

Sid Jhaveri
Sid Jhaveri 2017 年 6 月 6 日
You might want to use Arduino Support Package for MATLAB. For more information I would suggest referring the following links:

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!