Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Patrick Hritz
Patrick Hritz el 9 de Abr. de 2015
Respondida: Abhishek GS el 10 de Abr. de 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.

Respuestas (1)

Abhishek GS
Abhishek GS el 10 de Abr. de 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

Categorías

Más información sobre Arduino Hardware en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by