How to turn ON an output/function/GPIO for one second

조회 수: 1 (최근 30일)
Nitesh Ramdin
Nitesh Ramdin 2020년 11월 24일
답변: Prasanth Sunkara 2020년 11월 26일
Good day,
I am building a project for my degree. I have created a simple neural netowrk to classify images taken from my Pi Cam for an autonomous car.
I am at the piont where i have the trained model and based on the input image iether go FORWARD, RIGHT or LEFT. This is something that seems simple but i am unable to turn on the GPIO of 1sec. For some reason when an image is read it continueously turn on that respective GPIO out command.
I have attached my code if this make sense. i am a begginer.
%% Connect Raspberry Pi 4B & camera Board in Command Window
% mypi = raspi;
% mypi = raspi('192.168.43.157','pi','pi')
% cam = cameraboard(mypi,'Resolution','320x240');
%
%% Algorithm rev2
for i = 1:1
img = snapshot(cam);
% Preproccessing`````````````````````
imgNew = imresize(img,[227 227]); % resize image
[YPred,probs] = classify(trainedNetwork_1,imgNew);
figure(1);
imshow(imgNew)
label = YPred;
title(string(label) + ", " + num2str(100*max(probs),3) + "%");
end
if string(label) == "Forward"%fwd
for W = 1:1
writeDigitalPin(mypi, 5, 1);
writeDigitalPin(mypi, 6, 0);
writeDigitalPin(mypi, 27, 1);
writeDigitalPin(mypi, 22, 0);
pause(0.5);
end
elseif string(label) == "Left"%pivotleft
for Y = 1:1
writeDigitalPin(mypi, 5, 0);
writeDigitalPin(mypi, 6, 1);
writeDigitalPin(mypi, 27, 1);
writeDigitalPin(mypi, 22, 0);
pause(0.5);
end
elseif string(label) == "Right"%pivotleft
for Z = 1:1
writeDigitalPin(mypi, 5, 0);
writeDigitalPin(mypi, 6, 1);
writeDigitalPin(mypi, 27, 1);
writeDigitalPin(mypi, 22, 0);
pause(0.5);
end
end

답변 (1개)

Prasanth Sunkara
Prasanth Sunkara 2020년 11월 26일
https://in.mathworks.com/matlabcentral/answers/660278-how-to-turn-on-a-gpio-output-for-one-second#answer_556583

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by