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

1 view (last 30 days)
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

Answers (0)

Categories

Find more on MATLAB Support Package for Raspberry Pi Hardware in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!