フィルターのクリア

How do I translate a variable into HSV color values?

1 回表示 (過去 30 日間)
Shovnik Paul
Shovnik Paul 2022 年 7 月 15 日
コメント済み: William Rose 2022 年 7 月 15 日
I have this project where I am interfacing MATLAB with an Arduino board and reading input from an analog pin connected to a potentiometer. I want to use the voltage values read from the potentiometer to control the color of a rectangle. The voltage read is stored in the variable voltage
I have the following code:
while true
voltage = a.readVoltage('A0');
color = ??voltage??
fill([0 1 1 0], [0 0 1 1], color)
pause(0.1)
end
I would like to map the variable voltage to an HSV color value, specifically controlling the H(hue) parameter - so than when I turn my potentiometer wheel, I basically cycle through the different colors of the color wheel (ie change the hue). Is this possible? Any help is appreciated. Thanks.
Edit: the value of the voltage variable is in the range 0 - 5.

採用された回答

William Rose
William Rose 2022 年 7 月 15 日
Vmax=5;
while true
voltage = a.readVoltage('A0');
color = hsv2rgb(voltage/Vmax,1,1);
fill([0 1 1 0], [0 0 1 1], color);
pause(0.1)
end
Try the above. I tested it with the following modified code, which does not require an external input. It worked as expected, generating a whole range of colors from R to Y to G to C to B to M to R.
Vmax=5;
for i=0:24
voltage = i*Vmax/24;
color = hsv2rgb(voltage/Vmax,1,1);
fill([0 1 1 0], [0 0 1 1], color);
pause(0.5)
end
Good luck.
  2 件のコメント
Shovnik Paul
Shovnik Paul 2022 年 7 月 15 日
Excellent. Just what I needed. Thank you!
William Rose
William Rose 2022 年 7 月 15 日
@Shovnik Paul, you're welcome.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by