Week 15 Interface and Application Programming

This week, I explored how software and hardware can communicate creatively through tools like Processing and p5.js. It was exciting to see how simple physical inputs, like pressing a button, could generate dynamic visual responses on screen.

Learning Objectives

Group assignment:

1. Processing

1.1 🌀 What is Processing?

Processing is an open-source programming language and environment based on Java, mainly used in visual arts, interaction design, and creative coding. It's beginner-friendly and ideal for graphics, animations, and interaction with hardware like Arduino.

1.2 🎓 Project Example

Using a button on a microcontroller as input, we created an interactive sketch in Processing to display randomly generated shapes and colors on the canvas.

1.2.1 📦 Tools Used

1.2.2 🔁 Workflow

  1. User presses the button on the microcontroller
  2. Signal (e.g., "1\n") is sent via serial port
  3. Processing receives and checks the signal
  4. A new shape appears on canvas with:
    • Random type: circle, triangle, square, or polygon
    • Random size and color
Code1 for this week

1.3 🧠 Skills Learned

2. p5.js

2.1 🎨 Introduction to p5.js

p5.js is a creative coding library based on JavaScript, designed to make coding fun and accessible, especially for art, design, education, and beginners. It is the JavaScript version of Processing, led by Lauren McCarthy.

2.1.2 ✳️ Key Features

Feature Description
🎯 Beginner-Friendly Syntax similar to Processing, great for coding newbies
🧠 Creativity-Focused Perfect for visual arts, interaction design, data visualization, and sound
🌐 Web-Based Runs in browsers, no installation needed, easy sharing
📦 Extensive Libraries Supports images, sound, hardware (like Arduino), and 3D
💬 Active Community Plenty of open-source examples and learning resources

2.2 🎓 Project Examples

Created and embedded multiple p5.js sketches in a single page via the p5.js Web Editor.

3. 🌐 Web and HTML5 Canvas

3.1 Introduction to HTML5 Canvas and WebGL

The Web is one of the most widely used platforms today. To support rich interactivity and visuals, the W3C has standardized technologies such as HTML5, CSS, and JavaScript.

HTML5 Canvas and WebGL are core graphics APIs:

These APIs form the foundation of advanced frameworks like p5.js, offering both low-level control and creative flexibility.

3.2 🎓 Project Examples

3.2.1 Rotating Stars Around Earth

A WebGL-based animation that shows stars rotating around a 3D Earth. Includes adjustable sliders.

3.2.2 Stars Orbiting the Sun

Another WebGL animation where stars orbit a 3D Sun. Includes sliders for scale, speed, star size, and Z-depth.

Individual assignment:

4. Assignment: IR Distance Sensor Display via Serial Communication

Display IR Distance Sensor Data via Serial Communication between Arduino & Processing,this assignment is to read the distance value from an infrared sensor using Arduino, send the data to Processing via serial communication, and visualize the distance in real-time.

Tools: Arduino UNO, Sharp IR Sensor, Processing

4.11Hardware Setup

1

4.2Arduino Code

1

4.3 Processing Code

1

4.4 Running & Testing

📖 Reflection

In this assignment, I successfully implemented serial communication between Arduino and Processing to display real-time distance readings from an IR sensor. The main challenge was handling the serial data format and converting it properly in Processing. I solved this by using bufferUntil('\n') and trim() to clean the incoming string. This exercise helped me better understand sensor data processing and visual feedback using code.

CODE

Code4-1 for this week Code4-2 for this week