How to turn on a GPIO (Raspberry Pi 4B) for one second

3 Ansichten (letzte 30 Tage)
Nitesh Ramdin
Nitesh Ramdin am 24 Nov. 2020
Bearbeitet: Nitesh Ramdin am 24 Nov. 2020
Hi
I am currently building a Raspberry pi autonomous using Mathlab neural network. I am using a Pi camera to capture images. Once an image is captured, with either a forward, left or right output command.
How do i go about turning on the string(label) on for one second only.
I could maybe turn on the forward for one second and implement a stop command to all the pins.
I am a begginer at this and need some direction.
Here is my code as below:
%% 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

Antworten (0)

Kategorien

Mehr zu MATLAB Support Package for Raspberry Pi Hardware finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by