on matlab ///////////////////////////
function edit1_Callback(hObject, eventdata, handles) x =str2double(get(handles.edit1,'String'));
disp('Value entered: ')
disp(x) global s; delete(instrfind({'Port'},{'COM10'})); s=serial('COM10'); s.BaudRate=9600;
fopen(s);
disp('After OPEN')
disp(s)
fprintf(s,x);
fclose(s);
disp('After CLOSE')
disp(s)
/////////////// on arduino
const int ledpin=13; int recValue;
void setup() { Serial.begin(9600); pinMode(13, OUTPUT); }
void loop() { if(Serial.available()>0) { recValue=Serial.read();
if (recValue == 100) // If use will send value 100 from MATLAB then LED will turn ON { digitalWrite(ledpin, HIGH); } if(recValue == 101) // If use will send value 101 from MATLAB then LED will turn OFF { digitalWrite(ledpin, LOW); } } }
Best Answer