Arduino IDE code to Matlab

17 ビュー (過去 30 日間)
Farah Judith
Farah Judith 2022 年 12 月 4 日
コメント済み: Sameer Pujari 2022 年 12 月 7 日
Hey! I have a project and i'm currently stuck to "convert" the arduino IDE code to matlab code. anyone can help me? I attached the arduino IDE code below. anyway im using MATLABR2022b.
#include <Servo.h>
#define echoPin 4 //Echo Pin
#define trigPin 3 //Trigger Pin
Servo myservo;
long duration, distance;
const int servoPin = 9;
void setup() {
Serial.begin (9600);
myservo.attach(servoPin);
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
myservo.write(180);
delay(1000);
myservo.detach();
}
void loop() {
digitalWrite(trigPin, LOW);delayMicroseconds(2);
digitalWrite(trigPin, HIGH);delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
Serial.println(distance);
distance = duration/58.2;
if(distance <= 15) {
myservo.attach(servoPin);
myservo.write(30);
delay(575);
myservo.write(180);
delay(1500);
myservo.detach();
}
delay(13);
}
thanks! :)
  1 件のコメント
Sameer Pujari
Sameer Pujari 2022 年 12 月 7 日
Hello Farah
Arduino code logic can be implemented in matlab. Kindly install MATLAB arduino support package from here. Go through the example from this link to get started.
To use servo motor functions go through this documentation link.
Hope you helps !!

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

回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by