real time graph plotting using processing

edited June 2017 in Using Processing

i have to plot a graph in processing by the feedback from encoder motors of the bot. so i have two variables basically left motor encoder and right motor encoder. i planned to vary on in x-axis and another in y-axis. while i went through some of the codes on internet i found that, almost everyone has written the graph part code in serial event itself? so my first doubt is why do they write it in serial event() function rather than void draw()? another thing is when i tried to write my code for graph in void draw() it had a pseudo code something like this:

           xpos1=0,ypos1=height;
        void draw():
         line(xpos1,ypos1,xpos,height-ypos);// obviously the data(xpos,ypos) is mapped with the width and height of the processing ide window.
            xpos1=xpos;
            ypos1=height-ypos;
            if(xpos1>=width)
            {
              xpos1=0;
            }
            if(ypos1>=height)
            {
              ypos1=0;
            }

so i get to see only a small dot traversing on processing ide window and i cannot see the older path that my line has travelled which in the case of the sites which i described when wrote the similar piece of code in serial event() they had a whole graph getting made on the processing window. where am i getting wrong? please help me also is there any alternative to plot the graph using void draw()?i want to vary both xpos as well as ypos as i get two feedbacks form left motor and right motor. please help with the detailed answers. graph screenshot of my attempted graph in different frames screenshot of one of the graphs made by somewhat the similar code displayed above but written in the serial event() available on the internet:

Answers

Sign In or Register to comment.