Have you forgotten about Tools + Auto Format already?
int d2 = 0;
Consistency is a good habit. You don't seem to have developed that yet.
int pd1 = 0;
int pd2= 0;
int left = 0;
int right = 0;
You don't use these. Find the delete key.
Just in case it changed magically?
pd1 = d1;
Not used. Delete them.
Printing some different prefix in serialEvent() is necessary, so you know which prints happen in draw() and which happen in serialEvent().