Arduino 時間 VS A0ピンに入力される電圧をプロットする。

4 visualizzazioni (ultimi 30 giorni)
Shinsuke Okayasu
Shinsuke Okayasu il 14 Ott 2019
Risposto: Shinsuke Okayasu il 27 Ott 2019
Arduinoからの5V信号をポテンショメータで電圧を調整しています。
時間 vs 電圧をプロットする方法(下記①、②からplot関数でできると思うのですが・・・・)をご教示いただけないでしょうか。
①ワークスペースに時間を作成する方法
②while文が実行中のain(readVoltageのデータが格納される)が①に対応した電圧をワークスペースに作成する。
下記のコードを実行中です。
clear all;
a = arduino();
tic
while(toc<10)
ain = readVoltage(a,'A0');
fprintf('Voltage = %f',ain);
pause(0.5);
end
  1 Commento
Yoshio
Yoshio il 19 Ott 2019
①ワークスペースに計測時刻を記録
② ①の計測時刻に測定された電圧データをワークスペースに記録
と解釈してコードを作成してみます。

Accedi per commentare.

Risposta accettata

Yoshio
Yoshio il 19 Ott 2019
Modificato: Yoshio il 19 Ott 2019
OSのクロック機能を使うので厳密な測定にはなりませんが、以下のようにしてみてはどうでしょうか。
clear
a = arduino();
i = 0;
tic
while toc<10
i = i+1;
t(i) = toc;
ain(i) = readVoltage(a,'A0');
pause(0.5);
end
plot(t,ain)

Più risposte (1)

Shinsuke Okayasu
Shinsuke Okayasu il 27 Ott 2019
ありがとうございます。
ご指摘の方法で解決できました。ありがとうございます。

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!