How to convert arduino code to MATLAB code?

조회 수: 38 (최근 30일)
Victoria Martinez-Vivot
Victoria Martinez-Vivot 2016년 10월 10일
댓글: albin hussin 2018년 4월 11일
I need help translating this code from Arduino to MATLAB:
int tilt_s1 = 2; int tilt_s2 = 3;
void setup(){ pinMode(tilt_s1, INPUT); pinMode(tilt_s2, INPUT); Serial.begin(9600); }
void loop(){ int position = getTiltPos(); Serial.println(position); delay(200); //only here to slow down the serial output }
int getTiltPosition(){ int s1 = digitalRead(tilt_s1); int s2 = digitalRead(tilt_s2); return (s1 << 1) | s2; //bitwise math to combine the values
  댓글 수: 1
albin hussin
albin hussin 2018년 4월 11일
how to convert arduino code to matlab code. the code arduino this one const int brakePin = 9; const int directionPin = 12; const int obstacleDetect = A0; void setup() {
pinMode(directionPin, OUTPUT);
pinMode(obstacleDetect, INPUT);
pinMode(brakePin, OUTPUT);
digitalWrite(brakePin, LOW);
}
void loop() {
if (analogRead(obstacleDetect) > 50)
{
digitalWrite(brakePin, LOW);
}
else
{
digitalWrite(directionPin, HIGH);
delay (30000);
digitalWrite(brakePin, HIGH);
delay (3000);
digitalWrite(directionPin, LOW);
delay (30000);
digitalWrite(brakePin, HIGH);
}
}

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

답변 (1개)

Ankita Nargundkar
Ankita Nargundkar 2016년 10월 20일
Arduino code cannot be run directly on MATLAB by just changing a few keywords. Install MATLAB arduino support package from here. Go through the example from this link to get started.
Cheers!!

카테고리

Help CenterFile 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!

Translated by