Task #1:
My processing and Arduino framework provided a hyper-sensitive interaction, as could be seen in the two video recorded as following IMG_2934 IMG_2935. A minor mistake in the code that had generated this issue, the pinModes for the potentiometers were adjusted as “OUTPUT”. Thus, instead of recording the changes in resistance, it recorded as outputs the potentiometers.
Code for Processing:
import processing.serial.*; import osteele.processing.SerialRecord.*; int x1 = 0; int x2 = 1450; Serial serialPort; SerialRecord serialRecord; void setup() { fullScreen(); frameRate(30); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this,serialPort,2); } void draw() { background(0); noStroke(); if (x1 == 1450 && x2 == 0){ x1 = 0; x2 = 1450; serialRecord.values[0] = 0; serialRecord.values[1] = 1; serialRecord.send(); } if (x1 == 0 && x2 == 1450){ serialRecord.values[0] = 1; serialRecord.values[1] = 0; serialRecord.send(); } if (x1<1450) { circle(x1, 550, 50); x1=x1+50; x2 = 1450; serialRecord.values[0] = 0; serialRecord.values[1] = 0; serialRecord.send(); } else { circle(x2, 550, 50); x2=x2-50; serialRecord.values[0] = 0; serialRecord.values[1] = 0; serialRecord.send(); } }
Code for Arduino:
#include "SerialRecord.h" SerialRecord writer(2); int pinX = A0; int pinY = A1; void setup() { // put your setup code here, to run once: Serial.begin(9600); // pinMode(pinX,OUTPUT); // pinMode(pinY,OUTPUT); } void loop() { // put your main code here, to run repeatedly: int X = analogRead(pinX); int Y = analogRead(pinY); writer[0] = X; writer[1] = Y; writer.send(); delay(10); }
Task2:
Teammate: Tawan
Our code was absolutely fine throughout the process. The inefficiency was caused by some matters in Arduino and Processing system. Before we embedded the code that sent messages to Arduino, the circle bounced back and forth just fine after we simply managed the coordinates of borders. But once the code was embedded while there was no wrongs in grammar or mechanism of the Arduino code, Processing gave us all blank output when Arduino had sent the code of Arduino to Arduino Uno. It always said “port busy” in Processing. So, we shut it but the servo once received the message started moving forever non-stop. Thus, I have to forcefully made it stop by changing the Processing-sent value. After thousands of tries, I added two led lights to the servo to see if it was the problem with the servo. Surprisingly, the servos started to work fine. The interaction of the device was very much low-level, machine-to-machine, pale single-direction signal. However, it did stroke me that for Arduino-Processing artifacts, codes should be sent to the Arduino Uno first and I should shut the Arduino thoroughly before proceeding to Processing.
Recordings:
Code for Processing:
import processing.serial.*; import osteele.processing.SerialRecord.*; int x1 = 0; int x2 = 1000; Serial serialPort; SerialRecord serialRecord; void setup() { fullScreen(); frameRate(30); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this,serialPort,2); } void draw() { background(0); noStroke(); if (x1 == 1450 && x2 == 0){ x1 = 0; x2 = 1450; serialRecord.values[0] = 0; serialRecord.values[1] = 1; serialRecord.send(); } if (x1 == 0 && x2 == 1450){ serialRecord.values[0] = 1; serialRecord.values[1] = 0; serialRecord.send(); } if (x1<1450) { circle(x1, 550, 50); x1=x1+50; x2 = 1450; serialRecord.values[0] = 0; serialRecord.values[1] = 0; serialRecord.send(); } else { circle(x2, 550, 50); x2=x2-50; serialRecord.values[0] = 0; serialRecord.values[1] = 0; serialRecord.send(); } }
Code for Arduino:
#include "SerialRecord.h" #include <Servo.h> int led1 = 12; int led2 = 13; Servo servo1; Servo servo2; SerialRecord reader(2); int val = 180; void setup() { Serial.begin(9600); servo1.attach(7); servo2.attach(4); pinMode(led1,OUTPUT); pinMode(led2,OUTPUT); } void loop() { reader.read(); if (reader[0] == 1){ servo1.write(val); delay(100); servo1.write(0); reader[0] = 0; digitalWrite(led1, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(led1, LOW); // turn the LED off by making the voltage LOW delay(100); } if (reader[1] == 1){ servo2.write(val); delay(100); servo2.write(0); reader[1] = 0; digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW delay(100); } }