With the following codes, I have instructed Arduino to print the co-ordinations of the turntable rotations.
This is a screenshot of the coding for adding co-ordinations.
In Arduino (left box in screenshot), under the forward rotation code, the following code is added:
coords=coords+1;
Serial.println(coords);
And under the backwards rotation code, the following code is added:
coords=coords-1;
Serial.println(coords);
The 'Serial.println(coords);' is basically telling Arduino to print the co-ordinations of the rotation steps.
Now that Arduino is printing the co-ordinations. Processing will now tell Arduino to instruct the turntable to rotate to certain co-ordinations with the following code:
for(int lop=0;lop
rect(10+(lop*20),20,10,10);
The above code is basically telling Processing to draw a rectangle for each stated co-ordination. These will appear on the top left hand side of the Processing Run screen. See screenshot image at bottom of this code.
This next bit of coding is mouse control for each co-ordination stated. It is telling Arduino that when the mouse clicks one of the rectangles instruct the turntable to go to that specific co-ordination and stop.
if(mousePressed==false){
cansend=1;
}
if(mousePressed==true && cansend==1){
println("got click");
if((mouseY>20 && mouseY<30)>10+(lop*20) && mouseX<20+(lop*20))){
cansend=0;
clickedval=lop;
println("in range");
myport.write(coordinates[lop]);
println("c="+coordinates[lop]);
playing=0;
}
}
Addition code that has been added is the 'println' code. There are three in the above code:
println("got click");
println("in range");
println("c="+coordinates[lop]);
The first one is printed when clicked on the rectangle.
The second one is printing 'in range' when clicking on the rectangle.
The third one is printing 'c' and also the co-ordinations that have been clicked.
The 'println' is placed in the bottom left hand side of the Arduino program. See screenshot image below.
So far, I have got the turntable to rotate forwards and backwards, printing the co-ordinations and also telling the turntable to rotate to a specific co-ordination and stop.
My next step is to load an animation at the specific co-ordination when the turntable has stopped.
No comments:
Post a Comment