Hanwen Hu
22/11/2022
In this Recitation, due to the number of people and the configuration of props. I, Chen Ruiyang, and Zhuang Ruiqi formed a team to complete this task.
Step 1
First of all, in task 1, we were asked to make a simplified version of Processing drawing software according to the Etch-A-Sketch project. The first step is to make a circle that can control the position by using two potentiometers. I first built the circuit according to the instructions, and then made some changes according to the reference program, and this step was completed quickly.
The second part is to change the program from controlling circle movement to controlling line drawing. This process is not difficult, just use the line() function to replace it, and rewrite it a little bit. After spending some time, this step was completed relatively smoothly.
Step 2
Task 2 is a relatively advanced operation. First of all, we are asked to make a small ball that can “bounce” on the screen. This step is actually to set the ball to bounce back by itself when it touches the left and right boundaries of the screen. This step is not difficult to do after we carefully observe the teaching of the corresponding program. The problem came at the very last step – we needed to design a pair of motor driven rigs that would “hit” the ball on either side of the screen to match the motion of the ball, this procedure stuck our group for a while – either the rig was out of sync with the ball, or The ball is stuck at the starting point and cannot go out. Finally, we asked the professor for help, and the professor pointed out that there was a problem with our myservo() program, and after the modification, our project finally ran successfully. This was a fun collaborative challenge for our group.
Here is first step of task 2:
Here is our group’s final result:
Here is the code in Processing:
import processing.serial.*; import osteele.processing.SerialRecord.*; Serial serialPort; SerialRecord serialRecord; int x; int add=10; void setup(){ fullScreen(); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 115200); serialRecord = new SerialRecord(this, serialPort,1); } void draw(){ background(0); fill(255); stroke(0); circle(x,height/2,50); if (x>=width){ add=-add; serialRecord.values[0]=0; serialRecord.send(); } else if (x<0){ add=-add; serialRecord.values[0]=1; serialRecord.send(); } x=x+add; }
Here is the code in Arduino:
#include <Servo.h> #include "SerialRecord.h" SerialRecord reader(1); Servo myservo; Servo myservo2; int value; void setup() { // put your setup code here, to run once: Serial.begin(115200); myservo.attach(8); myservo2.attach(7); } void loop() { // put your main code here, to run repeatedly: if (reader.read()){ value=reader[0]; if (value==0){ myservo.write(100); delay(250); myservo.write(0); } else if (value==1){ myservo2.write(100); delay(250); myservo2.write(0); } } }