12

INTERFACE AND APPLICATION PROGRAMMING

This week we had to write an application that interfaces a user with an input &/or output device that we made.

Tools: Arduino IDE; Processing
Files: Visualization 1, Visualization 2
Date: 11.30.2022 (update: 12.22.2022)

Due to COVID, I was not able work on this assignment the week of. I did some simple visualization later by using Processing.

Processing

I used Processing for visualizing the data coming in from the potentiometer on the board I made for week 9. I am sending a percentage of the potentiometer's value (see code below) through Serial (USB). By connecting to the apporpriate port I am able to receive this value in Processing. After going through some examples, it seemed very much like coding in Arduino, so I played around with some examples and changed existing code to get the following results.
The first visualization was pretty straightforward to create. I just added a background in the code and delayed the Serial communication a little to allow smoother transition.
The second visualization is also based on the same potentiometer value, but for some reason the radius of the circle does not change like I expected it to. Rather, it flickers between two seemingly constant values, although the serial monitor of the potentiometer board is recording vastly different values. I tried changing the scale of the value, but was not very successful.

Arduino

The above programs were receiving code through Serial (USB) from the PCB with the potentiometer. The following was the Arduino code for the sending the potentiometer value to Processing.


    const int analogPin = 3;
    int value;      //variable that stores the raw analog reading
    int position;   //potentiometer position in percentage

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

    void loop() {
      value = analogRead(analogPin);           //perform raw analog reading
      position = map(value, 0, 1024, 0, 100);  //convert to percentage
      Serial.println(position);                //print converted reading to Serial
      delay(300);
    }