Can someone please help me convert this Arduino code to matlab code
조회 수: 1 (최근 30일)
이전 댓글 표시
int sensorPin = A0; // select the input pin for the potentiometer
float rawRange = 1024; // 3.3v
float logRange = 5.0; // 3.3v = 10^5 lux
void setup()
{
analogReference(EXTERNAL); //
Serial.begin(9600);
Serial.println("Adafruit Analog Light Sensor Test");
}
void loop()
{
// read the raw value from the sensor:
int rawValue = analogRead(sensorPin);
Serial.print("Raw = ");
Serial.print(rawValue);
Serial.print(" - Lux = ");
Serial.println(RawToLux(rawValue));
delay(1000);
}
float RawToLux(int raw)
{
float logLux = raw * logRange / rawRange;
return pow(10, logLux);
}
My biggest question is what would the "void" command be in Matlab? And also if it is still okay to use float in matlab. I feel like everything should work on matlab besides the void command. When I put the code into matlab the only problem it seems to have is with that void command. Please help!! THANK YOU!! I am using a GA1A12S202 Log-scale Analog Light Sensor and just simply want the sensor to work using matlab code.
댓글 수: 0
답변 (1개)
Abhishek GS
2015년 4월 10일
Hi Patrick Hritz,
One thing to know is that the arduino code cannot be run directly on MATLAB as it is by just changing a few keywords. First install the MATLAB arduino support package from here . Go through the example from this link to help you get started.
Also, the default data type in MATLAB in double. So you do not have to use 'float' explicitly.
Cheers, Abhishek
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!