How do I make the Pin I select a variable

I have this code asking me which colour I want r,g,b
(ColourAsk)
x= input('What Colour? (r,g,b)','s');
y= input('What Second Colour? (r,g,b)','s');
if x == 'r'
x='D5';
elseif x =='g'
x= 'D9';
else
x= 'D6';
end
if y == 'r'
y='D5';
elseif y =='g'
y= 'D9';
else
y= 'D6';
end
This then goes to here where it is written:
(setgrad)
writePWMDutyCycle(a,x,grad)
writePWMDutyCycle(a,y,grad2)
writePWMDutyCycle(a,z,0)
pause(0.0000000000001)
Which then goes to here to control the Pins and slowly dim/brighten the lights connected to them:
(Askgrad)
ColourAsk
grad=1;
grad2=0;
while true
%main program loop
while grad > 0.01
setgrad
grad = grad - 0.01;
grad2 = grad2 + 0.01;
end
while grad2 > 0.01
setgrad
grad = grad + 0.01;
grad2 = grad2 - 0.01;
end
end
I get an Error telling me that in setgrad I have an invalid Pin Format and that in Askgrad line 7 is an error. How do I make it so that I can use a variable to set which pin is first and second.

Respuestas (1)

Anmol Dhiman
Anmol Dhiman el 8 de Abr. de 2020

0 votos

Hi Cole,
It is evident that the error seems to be in setgrad function. Inside setgrad, you are calling multiple functions. THe problem might be in one of those functions. I will suggest you to check what exaclty is the pin format asked for. I maybe able to help you , if you share the code for functions within setgrad.
Thanks,
Anmol Dhiman

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Productos

Versión

R2017a

Preguntada:

el 5 de Abr. de 2020

Respondida:

el 8 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by