How to do Arduino serial communication with MATLAB GUI Push button?
3 ビュー (過去 30 日間)
古いコメントを表示
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 ........
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で MATLAB Support Package for Arduino Hardware についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!