Hi Arduinos!
I am working on my project and got stuck at sending variables from Matlab to Arduino.
What I want to do is to send this value from Matlab: 255,100,0,100,175,300
to fill 6 variables in Arduino so I can setup my PORTD properties. I want to generate signal like this on output:
I understand I can use Serial.parseint to fill my variables, but it is not really working, and since I'm really new to programming I don't know where I made a mistake. Can you PLEASE help me?
Arduino code looks like this:
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
void setup()
{
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(Serial.available()>0) // if there is data to read
{
a=Serial.parseInt(); // read data
b=Serial.parseInt();
c=Serial.parseInt();
d=Serial.parseInt();
e=Serial.parseInt();
f=Serial.parseInt();
PORTD = a;
delay = b;
PORTD = c;
delay = d;
PORTD = e;
delay = f;
}
}
Matlab code:
data=['255,100,0,100,175,300'];
global s;
s=serial('COM4','BaudRate',9600);
fopen(s);
fprintf(s,data);
fclose(s);