Task 1
At first, I did not know how to draw the line. And then, reminded of the position of “background” would work, I put the background function into setup. Then it still didn’t work, I realized it is not enough, so with my partner’s help, I added the “pre” function to my code.
This process of reflection involved users changing the direction of the line with their own control, it is actually hard to draw a picture with it.
At first, I tried to write the code with the “if” function, and it was not working, then my partner tried it with multi-variables with complex conditions, and it was not working either.
After class, I figure out the right way of drawing the bouncing ball, but we didn’t have time to add the servos.
I would call it an interaction between Arduino and Processing but not between devices and humans. I actually did not see a high degree of interaction in this project.🤣
/** * Example sketch for the SerialRecord library for Processing. * * Maps the horizontal and vertical position of the mouse on the canvas to the * range 0…1023, and sends them to the serial port. float y = 0; float speedY = 0; */ import processing.serial.*; import osteele.processing.SerialRecord.*; Serial serialPort; SerialRecord serialRecord; float y = 0; float speedY = 0; void setup() { size (1000,1000); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); // In order to send a different number of values, modify the number `2` on the // next line to the number values to send. In this case, the corresponding // number in the Arduino sketch should be modified as well. serialRecord = new SerialRecord(this, serialPort, 2); } void draw() { background(0); y = y + speedY; speedY += 0.03; if (y<0||y>height){ speedY = speedY * -1; } fill(255); circle(width/2, y, 50); // store some values in serialTransport.values, and send them to the Arduino serialRecord.values[0] = int(map(y,0, 1000, 0, 1023)); serialRecord.send(); }