I have a code for data acquisition n plotting from one sensor how do write the code for three sensors such that I plot three graphs of different color in same figure

clear all
close all
clc;
a = arduino();
tmax = 50;
figure(1),
grid on,
title('pulse sensor Analog Voltage Real Time Data Graph')
xlabel ('Time (s)'), ylabel('Voltage');
axis([0 tmax+1 -0.5 5.5]);
k = 0;
v = 0;
t = 0;
tic
while toc<= tmax
k = k + 1;
v(k) = readVoltage(a,'A0');
t(k) = toc;
if k > 1
line([t(k-1) t(k)],[v(k-1) v(k)]);
drawnow;
end
end

댓글 수: 3

#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>
const int OUTPUT_TYPE = SERIAL_PLOTTER;
/*
Number of PulseSensor devices we're reading from.
*/
const int PULSE_SENSOR_COUNT = 3;
const int PULSE_INPUT0 = A0;
const int PULSE_BLINK0 = 13; // Pin 13 is the on-board LED
const int PULSE_FADE0 = 5;
const int PULSE_INPUT1 = A1;
const int PULSE_BLINK1 = 12;
const int PULSE_FADE1 = 11;
const int PULSE_INPUT2 = A2;
const int PULSE_BLINK2 = 10; // Pin 13 is the on-board LED
const int PULSE_FADE2 = 9;
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
/*
All the PulseSensor Playground functions.
We tell it how many PulseSensors we're using.
*/
PulseSensorPlayground pulseSensor(PULSE_SENSOR_COUNT);
void setup() {
Serial.begin(250000);
pulseSensor.analogInput(PULSE_INPUT0, 0);
pulseSensor.blinkOnPulse(PULSE_BLINK0, 0);
pulseSensor.fadeOnPulse(PULSE_FADE0, 0);
pulseSensor.analogInput(PULSE_INPUT1, 1);
pulseSensor.blinkOnPulse(PULSE_BLINK1, 1);
pulseSensor.fadeOnPulse(PULSE_FADE1, 1);
pulseSensor.analogInput(PULSE_INPUT2, 2);
pulseSensor.blinkOnPulse(PULSE_BLINK2, 2);
pulseSensor.fadeOnPulse(PULSE_FADE2, 2);
pulseSensor.setSerial(Serial);
pulseSensor.setOutputType(OUTPUT_TYPE);
pulseSensor.setThreshold(THRESHOLD);
// Now that everything is ready, start reading the PulseSensor signal.
if (!pulseSensor.begin()) {
for (;;) {
// Flash the led to show things didn't work.
digitalWrite(PULSE_BLINK0, LOW);
delay(50);
digitalWrite(PULSE_BLINK0, HIGH);
delay(50);
}
}
}
void loop() {
delay(200);
// write the latest sample to Serial.
pulseSensor.outputSample();
for (int i = 0; i < PULSE_SENSOR_COUNT; ++i) {
if (pulseSensor.sawStartOfBeat(i)) {
pulseSensor.outputBeat(i);
}
}
}
I have Arduino code, I want to draw it instantly in matlab. Can you help me
The frameworks people have posted should work, provided that you do not need more than about 40 Hz. (But I do recommend animatedline() instead of continually doing line())

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

line() can accept a 'color' option.
However, it is inefficient to draw a line between every pair of points. You should look at animatedline() which permits you to addpoints()
clear all
close all
clc;
a = arduino();
tmax = 50;
figure(1),
grid on,
title('pulse redings')
xlabel ('Time (s)'), ylabel('Voltage');
axis([0 tmax+1 -0.5 5.5]);
c= 0;
v= 0;
p=0;
k=0;
t = 0;
tic
while toc<= tmax
c = c + 1;
v(c) = readVoltage(a,'A0');
w(c) = readVoltage(a,'A1');
x(c) = readVoltage(a,'A2');
t(c) = toc;
if c > 1
line([t(c-1) t(c)],[v(c-1) v(c)],'color','blue');
hold on
line([t(c-1) t(c)],[p(c-1) p(c)],'color','red');
hold on
line([t(c-1) t(c)],[k(c-1) k(c)],'color','green');
drawnow;
end
end

댓글 수: 1

thanks for the answers .... managed to figure it out this is the code if someone is in a simillar situation

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by