In exemplul de mai jos am legat la un Arduino doua potentiometre si am facut capturi de ecran in timp ce le roteam de zor ;)
/*
SimPlot Demo
Samples Analog Input and sends them over serial port to be plotted in SimPlot.
This Demo software uses the default serial port "Serial".
Upto to 4 channels of data can be plotted.
For details of SimPlot go to www.negtronics.com/simplot
Simplificata pentru postare pe blog - doua canale
Versiunea completa este la pagina de mai sus
*/
void setup()
{
Serial.begin(57600);
}
int buffer[20]; //Buffer needed to store data packet for transmission
int data1;
int data2;
void loop()
{
//Read Analog channels. You can connect accelerometer, gyro, temperature sensor etc to these channels
data1 = analogRead(0);
data2 = analogRead(1);
plot(data1,data2); //Plots 2 channels of data
delay(10); //Read and plot analog inputs every 10ms.
}
//Function that takes 2 integer values and generates a packet to be sent to SimPlot.
void plot(int data1, int data2)
{
int pktSize;
buffer[0] = 0xCDAB; //SimPlot packet header. Indicates start of data packet
buffer[1] = 2*sizeof(int); //Size of data in bytes. Does not include the header and size fields
buffer[2] = data1;
buffer[3] = data2;
pktSize = 2 + 2 + (2*sizeof(int)); //Header bytes + size field bytes + data
//IMPORTANT: Change to serial port that is connected to PC
Serial.write((uint8_t * )buffer, pktSize);
}



Niciun comentariu:
Trimiteți un comentariu