Hi to everyone...
Below you will see that with these codes (Arduino+Processing) i convert an analog signal to digital with delta modulation and then i graph the bits which accept Arduino. I would like to know if i can in processing code to create the bits graph and also the analol signal graph together.(code?)(not to ''paint'' the bits only which i do already, but to create and the line of the signal)
HERE Are The Codes
ARDUINO
int currReading;
int prevReading = 0;
int val = 0;
void setup()
{Serial.begin(9600); }
void loop()
{val = analogRead(0);
Serial.print(0xff, BYTE);
Serial.print((val >> 8) & 0xff, BYTE);
Serial.print(val & 0xff, BYTE);
currReading = analogRead(0);
int delta = currReading - prevReading;
Serial.println(delta);
prevReading = currReading;
delay(10); }
Processing
import processing.serial.*;
Serial myPort;
int val;
int valx;
int xd = 1;
int stxr;
int stxg;
int stxb;
int xdd;
int xdc;
void setup()
{size(700, 256);
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
background(0);}
void draw()
{while (myPort.available() >= 3) {
if (myPort.read() == 0xff)
val = (myPort.read() << 8) | (myPort.read());
valx = val / 4 ; }
xdd = xd / 2 ;
xdc =xd - xdd * 2 ;
if (xdc == 0 )
{stxr = 204 ; stxg = 233 ; stxb = 248;}
else {stxr = 0 ; stxg = 146 ; stxb = 218;} ;
println (xdc) ;
stroke(stxr, stxg, stxb);
line(xd, height, xd, height - valx);
if (xd >= width)
{xd = 0;
background(0); }
else
{xd++;}}