How to do Arduino serial communication with MATLAB GUI Push button?

1 vue (au cours des 30 derniers jours)
VALARMATHY K
VALARMATHY K le 11 Oct 2017
This is the code which is available in Matlab central
s=serial('COM','BAUD', 9600);
fopen(s);
for m=1:10
servalue= input('Enter the value 100 to turn ON LED & 101 to turn OFF LED :');
fprintf(s,servalue);
end
*I want to use it with push button in GUI
This is My code:*
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a
s=serial('COM40','BAUD', 9600);
fopen(s);
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a
servervalue= 100;
fprintf('%d\n',servervalue);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a
servervalue= 101;
fprintf('%d\n',servervalue);
Code for 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)
{
digitalWrite(ledpin, HIGH);
}
if(recValue == 101)
{
digitalWrite(ledpin, LOW);
}
}
}
it print the value 100 when i press button2 and print value 101 when i press button3 but there is no response in LED?
Any one please help me to do so ........

Réponses (0)

Catégories

En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by