Amelia’s Tenth Documentation Blog

1. in this project, we are going to use a physical sensor to control media on processing to change. in my project, I use the potentiometer to control the location of the media in processing. when I turn the nob, the picture’s position will change. we hope to learn how to control the media through Arduino.

2. the process went as planned. I first opened the example to send and receive the variables on processing and Arduino. then, I change the code so that instead of sending the position of the ball, I’m sending the position of the picture I put in the file of the processing. after changing the code, I connect the Arduino to the computer and test it. it worked. what didn’t go as planned is that the first time I connected the Arduino, I connect the middle one to the ground so that there was a shortcut there and my potentiometer went very hot. 

3. what I learned is how to control the media through Arduino. I also remembered deeply the middle of the potentiometer is used for the pin only.

4. the following is my code and the video.

/**
 * Example sketch for the SerialRecord library for Processing.
 *
 * Receives two integers from the serial port, and uses them to control the x
 * and y position of a circle on the canvas.
 */

import processing.serial.*;
import osteele.processing.SerialRecord.*;
PImage photo;

Serial serialPort;
SerialRecord serialRecord;

void setup() {
  size(500, 500);

  String serialPortName = SerialUtils.findArduinoPort();
  serialPort = new Serial(this, serialPortName, 9600);
  photo = loadImage("syt.jpeg");
  // If the Arduino sketch sends a different number of values, modify the number
  // `2` on the next line to match the number of values that it sends.
  serialRecord = new SerialRecord(this, serialPort, 2);
}

void draw() {
  background(0);
  int value1 = serialRecord.values[0];
  int value2 = serialRecord.values[1];
  
  float x = map(value1, 0, 1024, 0, width);
  float y = map(value2, 0, 1024, 0, height);
  image(photo, x, y);
  serialRecord.read();

} 
/*
  SendMultipleValues

  Reads an analog input on pin 0, and sends a record that contains two values:

  1. Value of `millis()`, modulo 1024.
  2. The analog value that is read from pin 0.

  If you attach a potentiometer to pin 0, you can control this value by moving
  the pot.

  This sketch pairs well with the RecieveMultipleValues example from the
  Processing SerialRecord library
  <https://osteele.github.io/Processing_SerialRecord/>.

  Things to try:
  - Connect a second potentiometer to the Arduino, and send the values from both
    potentiometers, instead of send a value that is based on `millis()`.
  - Send the value from another sensor, such as temperature or proximity.

  by Oliver Steele, 2020-2022

  This example code is in the public domain.
*/

#include "SerialRecord.h"

// Change this number to send a different number of values
SerialRecord writer(2);

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);

  writer[0] = millis() % 1024;
  writer[1] = sensorValue;
  writer.send();

  // This delay slows down the loop, so that it runs less frequently. This can
  // make it easier to debug the sketch, because new values are printed at a
  // slower rate.
  delay(10);
}
 

Leave a Reply

Your email address will not be published. Required fields are marked *