i am using myrpi variable inside a while loop. i am gettng an error as undefine function or variable myrpi. code is " if isempty(bbox) disp('No one is Here turn off all connection')else disp('someone is here in the room')"Please help

조회 수: 2 (최근 30일)
code:
if isempty(bbox)
disp('No one is Here turn off all connection')
else
disp('someone is here in the room turn on supply ')
for i = 1:10
writeDigitalPin(rpi, 4, 1);
pause(0.5);
writeDigitalPin(rpi, 4, 0);
pause(0.5);
end
error:
Undefined function or variable 'rpi'.
Error in finalprogram1 (line 27)
writeDigitalPin(rpi, 4, 1);

채택된 답변

Von Duesenberg
Von Duesenberg 2018년 4월 9일
편집: Von Duesenberg 2018년 4월 9일
I am not sure what the first clearvars is doing(the formatting of your code as it appears here probably lacks a number of end of lines characters) but the second one clears all variables except a variable called mypi... you called your raspi object rpi (not mypi), so it gets deleted by the call to clearvars. In other words, the following should do the trick:
clearvars -except rpi myCam flag

추가 답변 (1개)

sanjay singh
sanjay singh 2018년 4월 8일
편집: Walter Roberson 2018년 4월 9일
this is the whole program , i have initialized the rpi variable
%setup Raspberry pi
clearvars
rpi= raspi('192.168.43.142','pi','raspberry');
myCam= cameraboard(rpi,'Resolution','640x480');
%camera snapshoot and detect face
flag=1;
while flag
clearvars -except mypi myCam flag
mysnap= snapshot(myCam);
imshow(mysnap);
hold on
faceDetector = vision.CascadeObjectDetector();
bbox =step(faceDetector,mysnap);
imageout=insertObjectAnnotation(mysnap,'rectangle',bbox,'face');
imshow(imageout);
title('Detected face');
drawnow
if isempty(bbox)
disp('No one is Here turn off all connection')
writeDigitalPin(rpi, 4, 0);
pause(0.5);
else
disp('someone is here in the room turn on supply ')
for i = 1:10
writeDigitalPin(rpi, 4, 1);
pause(0.5);
end
end
end

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Raspberry Pi Hardware에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by