I collaborated with Aakif for these in-class exercises. And we tried to keep it as simple as possible.
Exercise 1
/* Week 11.2 bidi serial example * Originally by Aaron Sherwood * Modified by Mangtronix */ let rVal = 0; let alpha = 255; let left = 0; // True (1) if mouse is being clicked on left side of screen let right = 0; // True (1) if mouse is being clicked on right side of screen function setup() { createCanvas(640, 480); textSize(18); } function draw() { // one value from Arduino controls the background's red color background(map(rVal, 0, 1023, 0, 255), 255, 255); ellipse(rVal +25,height/2, 50,55); // makes an ellipse that moves with resistor // the other value controls the text's transparency value fill(255, 0, 255, map(alpha, 0, 1023, 0, 255)); if (!serialActive) { text("Press Space Bar to select Serial Port", 20, 30); } else { text("Connected", 20, 30); // Print the current values text('rVal = ' + str(rVal), 20, 50); text('alpha = ' + str(alpha), 20, 70); } // click on one side of the screen, one LED will light up // click on the other side, the other LED will light up if (mouseIsPressed) { if (mouseX <= width / 2) { left = 1; } else { right = 1; } } else { left = right = 0; } } function keyPressed() { if (key == " ") { // important to have in order to start the serial connection!! setUpSerial(); } } // This function will be called by the web-serial library // with each new *line* of data. The serial library reads // the data until the newline and then gives it to us through // this callback function function readSerial(data) { //////////////////////////////////// //READ FROM ARDUINO HERE //////////////////////////////////// if (data != null) { // make sure there is actually a message // split the message let fromArduino = split(trim(data), ","); // if the right length, then proceed if (fromArduino.length == 2) { // only store values here // do everything with those values in the main draw loop // We take the string we get from Arduino and explicitly // convert it to a number by using int() // e.g. "103" becomes 103 rVal = int(fromArduino[0]); alpha = int(fromArduino[1]); } ////////////////////////////////// //SEND TO ARDUINO HERE (handshake) ////////////////////////////////// let sendToArduino = left + "," + right + "\n"; writeSerial(sendToArduino); } }
(Arduino Code Remains same as given in class)
Exercise 2
One of the LED’s brightness is changed by mouseX and the other’s by mouse Y.
/* Week 11.2 bidi serial example * Originally by Aaron Sherwood * Modified by Mangtronix */ let rVal = 0; let alpha = 255; let left = 0; // True (1) if mouse is being clicked on left side of screen let right = 0; // True (1) if mouse is being clicked on right side of screen function setup() { createCanvas(255, 255); textSize(18); } function draw() { // one value from Arduino controls the background's red color background(map(rVal, 0, 1023, 0, 255), 255, 255); // the other value controls the text's transparency value fill(255, 0, 255, map(alpha, 0, 1023, 0, 255)); if (!serialActive) { text("Press Space Bar to select Serial Port", 20, 30); } else { text("Connected", 20, 30); // Print the current values text('rVal = ' + str(rVal), 20, 50); text('alpha = ' + str(alpha), 20, 70); } // click on one side of the screen, one LED will light up // click on the other side, the other LED will light up if (mouseIsPressed) { if (mouseX <= width / 2) { left = 1; } else { right = 1; } } else { left = right = 0; } } function keyPressed() { if (key == " ") { // important to have in order to start the serial connection!! setUpSerial(); } } // This function will be called by the web-serial library // with each new *line* of data. The serial library reads // the data until the newline and then gives it to us through // this callback function function readSerial(data) { //////////////////////////////////// //READ FROM ARDUINO HERE //////////////////////////////////// if (data != null) { // make sure there is actually a message // split the message let fromArduino = split(trim(data), ","); // if the right length, then proceed if (fromArduino.length == 2) { // only store values here // do everything with those values in the main draw loop // We take the string we get from Arduino and explicitly // convert it to a number by using int() // e.g. "103" becomes 103 rVal = int(fromArduino[0]); alpha = int(fromArduino[1]); } ////////////////////////////////// //SEND TO ARDUINO HERE (handshake) ////////////////////////////////// let sendToArduino = mouseX + "," + mouseY + "\n"; writeSerial(sendToArduino); } }
int leftLedPin = 3; int rightLedPin = 5; void setup() { // Start serial communication so we can send data // over the USB connection to our p5js sketch Serial.begin(9600); // We'll use the builtin LED as a status output. // We can't use the serial monitor since the serial connection is // used to communicate to p5js and only one application on the computer // can use a serial port at once. pinMode(LED_BUILTIN, OUTPUT); // Outputs on these pins pinMode(leftLedPin, OUTPUT); pinMode(rightLedPin, OUTPUT); // Blink them so we can check the wiring digitalWrite(leftLedPin, HIGH); digitalWrite(rightLedPin, HIGH); delay(200); digitalWrite(leftLedPin, LOW); digitalWrite(rightLedPin, LOW); // start the handshake while (Serial.available() <= 0) { digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data Serial.println("0,0"); // send a starting message delay(300); // wait 1/3 second digitalWrite(LED_BUILTIN, LOW); delay(50); } } void loop() { // wait for data from p5 before doing something while (Serial.available()) { digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data int xPos = Serial.parseInt(); int yPos = Serial.parseInt(); if (Serial.read() == '\n') { analogWrite(leftLedPin, xPos); analogWrite(rightLedPin, yPos); int sensor = analogRead(A0); delay(5); int sensor2 = analogRead(A1); delay(5); Serial.print(sensor); Serial.print(','); Serial.println(sensor2); } } digitalWrite(LED_BUILTIN, LOW); }
Exercise 3
When dark, wind blows towards the left and when it is bright, wind blows towards the right.
int leftLedPin = 2; int rightLedPin = 5; void setup() { // Start serial communication so we can send data // over the USB connection to our p5js sketch Serial.begin(9600); // We'll use the builtin LED as a status output. // We can't use the serial monitor since the serial connection is // used to communicate to p5js and only one application on the computer // can use a serial port at once. pinMode(LED_BUILTIN, OUTPUT); // Outputs on these pins pinMode(leftLedPin, OUTPUT); pinMode(rightLedPin, OUTPUT); // Blink them so we can check the wiring digitalWrite(leftLedPin, HIGH); digitalWrite(rightLedPin, HIGH); delay(200); digitalWrite(leftLedPin, LOW); digitalWrite(rightLedPin, LOW); // start the handshake while (Serial.available() <= 0) { digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data Serial.println("0,0"); // send a starting message delay(300); // wait 1/3 second digitalWrite(LED_BUILTIN, LOW); delay(50); } } void loop() { // wait for data from p5 before doing something while (Serial.available()) { digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data int LED_STATE = Serial.parseInt(); //int right = Serial.parseInt(); if (Serial.read() == '\n') { digitalWrite(rightLedPin, LED_STATE); int sensor2 = analogRead(A1); delay(5); Serial.print(sensor2); Serial.print(','); Serial.println('Y'); } } digitalWrite(LED_BUILTIN, LOW); }
These exercises helped me better understand how Arduino and p5 communicate through signals and how the data is best interpreted by the handshake, splitting and trimming.
Final Project Proposal
I want to build a robot that can learn its way around a certain maze/place through its Reinforcement Learning algorithm. I would use a python module for it to train and collect data and then transfer it to the Arduino and track the best possible path it finds on p5.js. I intend to use IR Sensors and a Bluetooth Module booked from the IM lab, Drills, Hand Saw, Soldering Stations, etc.
Reading Reflection
In the reading, the author delves into the complex challenges of designing for disability under the concept of universal design. This approach, aimed at creating products and services that are accessible and usable by as many people as possible, regardless of their abilities or disabilities, is critically analyzed. The text presents a compelling argument about the tension between creating a universally inclusive product and the risk of it becoming overly complex and less effective. The example of James Leckey’s furniture design for children with cerebral palsy highlights this tension. Leckey’s shift from universal solutions to more focused, adaptable products suggests that universal design might sometimes compromise the effectiveness and aesthetic appeal of a product. This case supports the argument that a balance must be struck between universality and simplicity, emphasizing the importance of targeted, user-centric design over a one-size-fits-all approach.
Regarding bias, the author seems to approach the subject with a balanced perspective, acknowledging the merits of universal design while also highlighting its potential drawbacks. This balanced view suggests a lack of significant bias, as the author presents both sides of the argument fairly. The reading has reshaped my understanding of universal design, highlighting its complexity and the crucial need for balance in design decisions. It raises questions about how designers can effectively balance the diverse needs and preferences of users without compromising the functionality and aesthetics of a product. Additionally, it prompts a consideration of how businesses can economically justify producing more specialized products while still catering to a broad market. This reading has made me more aware of the nuanced challenges in designing for inclusivity and the importance of considering the diverse needs of all potential users.