Can someone please help me convert this Arduino code to matlab code

10 Ansichten (letzte 30 Tage)
Patrick Hritz
Patrick Hritz am 9 Apr. 2015
Beantwortet: Abhishek GS am 10 Apr. 2015
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.

Antworten (1)

Abhishek GS
Abhishek GS am 10 Apr. 2015
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

Kategorien

Mehr zu Arduino Hardware finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by