i have been working on this project many days but i did not succeed, please help.
i want to send from the matlab gui 3 variables (each long byte) and receive them in arduino.
i found this code, but it did not work, any clue where is the problem?
matlab part: (i opened gui - insert a edit text and placed this code)
function stepInput_Callback(hObject, eventdata, handles)
xyz = get(hObject,'String');
disp('Value entered: ')
disp(xyz)
global COM;
global s;
s = serial(COM,'BaudRate',9600);
fopen(s);
disp('After OPEN')
disp(s)
fprintf(s,xyz);
fclose(s);
disp('After CLOSE')
disp(s)
arduino part:
int x;
int y;
int z;
void setup() {
pinMode(2,OUTPUT);
pinMode(6,OUTPUT);
pinMode(10,OUTPUT);
Serial.begin(9600);
}void loop() {
if (Serial.available()) // check if Serial data is available to read
{
x = Serial.parseInt();
y = Serial.parseInt();
z = Serial.parseInt();
if (Serial.read() == '\n') // check if ENTER has been pressed (newline)
{
digitalWrite(2,1);
delay(x);
digitalWrite(6,1);
delay(y);
digitalWrite(10,1);
delay(z);
digitalWrite(10,0);
delay(z);
digitalWrite(6,0);
delay(y);
digitalWrite(2,0);
delay(x);
}
}
}