change this arduino code into matlab code:
Mostrar comentarios más antiguos
int pd=2;
int buzz=13;
int senRead=0;
int limit=1000;
void setup()
{
pinMode(pd,OUTPUT);
pinMode(buzz,OUTPUT);
digitalWrite(pd,HIGH);
digitalWrite(buzz,LOW);
Serial.begin(9600);
}
void loop()
{
int val=analogRead(senRead);
Serial.println(val);
if(val <= limit)
{
digitalWrite(buzz,HIGH);
}
else if(val > limit)
{
digitalWrite(buzz,LOW);
delay(20);
}
}
1 comentario
Walter Roberson
el 24 de Sept. de 2015
The "if" after the else is redundant. With the int data type, every val that is not <= limit must be > limit.
If you were using floating point data types instead, then there is one case where both conditions can be false, and that is if val is NaN (Not A Number).
Respuestas (1)
Madhu Govindarajan
el 24 de Sept. de 2015
Editada: Walter Roberson
el 24 de Sept. de 2015
I have not tried this out, hope this works out. I am using R2015a syntaxes for which you will have to download the support package. If it does not, please post any error messages that you get.
pd = 'D2';
buzz = 'D13';
senRead = 'A0';
limit = 1000;
a = arduino;
configurePin(a, pd, 'DigitalOutput')
configurePin(a, buzz, 'DigitalOutput')
writeDigitalPin(a, pd, 1);
writeDigitalPin(a, buzz, 0);
for i = 1:1000
val = readVoltage(a,senRead)
if val <= limit
writeDigitalPin(a, buzz, 1);
elseif val > limit
writeDigitalPin(a, buzz, 0);
pause(0.002);
end
end
Categorías
Más información sobre Get Started with MATLAB Support Package for Arduino Hardware en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!