Objectives

Individual assignment: write an application that interfaces a user with an input &/or output device that you made

Group assignment: compare as many tool options as possible

14. Interface and application programming

UI and its types

A User Interface (UI) is the medium through which a user interacts with a device, software application, or system. It includes all the controls and visual elements that allow users to:

The goal of UI design is to make these interactions intuitive, efficient, and visually pleasing ultimately enhancing the overall User Experience (UX).

Graphical User Interface (GUI): Uses visual components like windows, icons, buttons, and menus. Users interact via mouse, keyboard, touchscreen, etc.

Command-Line Interface (CLI): A text-based interface where users type commands. Efficient for experienced users, especially in system administration and development.

Touchscreen Interface: Found in phones, tablets, kiosks, and more. Enables intuitive interaction through gestures like tapping, swiping, and pinching.

Voice User Interface (VUI) Allows users to interact using spoken commands. Examples: Siri, Alexa, Google Assistant.

Virtual and Augmented Reality Interfaces (VR/AR)

UI for interactive website

As a part of explaining interface, I tried the codes provided by the instructor.

1.Button

                              
                              

      <!DOCTYPE html>
      <html lang="en">
         
      <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Button</title>
      </head>
      <body>
          button style="margin: auto;" id="press">Click me/button>
          <p id="para">

<script> const button = document.getElementById('press'); const para = document.getElementById('para'); button.addEventListener('click' , function(e){ para.textContent = para.textContent + 'Clicked'; document.getElementById('para').style.color = 'red' button.style.backgroundColor = button.style.backgroundColor === 'red' ? 'gray' : 'red'; });

2.Realtimeinput

        
        <input type="text" id="myInput" name="myInput">
        <div id="output"></div>
        
        <script>
            const inputElement = document.getElementById('myInput');
            const outputElement = document.getElementById('output');
        
            inputElement.addEventListener('input', function(event) {
                const inputValue = event.target.value;
                outputElement.textContent = 'My name is ' + inputValue;
            
            //const input = (e.target.Value).split("");
            if (inputValue.length>8){
              outputElement.style.color = 'red'
            }else if(inputValue.length>4){
              outputElement.style.color = 'blue';
            }else{
              outputElement.style.color = 'green'
        
              }
            });
        
        
            
            </script> 
      

KODULAR

Kodular is a free, drag-and-drop platform that enables users to create Android applications without writing traditional code. It features a visual interface where users can design apps by assembling components like buttons, sensors, and layouts, and it employs a block-based programming system based on Google’s Blockly, similar to MIT App Inventor and Scratch. This approach allows beginners and non-programmers to build functional Android apps using visual logic blocks instead of text-based code. While Kodular itself operates through these visual blocks, the apps created with it are ultimately compiled into Java code for Android. To facilitate real-time testing and debugging, Kodular provides a companion app called Kodular Companion. This app allows developers to instantly preview and interact with their projects on an Android device without the need to compile and install the APK each time. By scanning a QR code or entering a code generated in the Kodular creator interface, users can connect their device to the project and see live updates as they modify their app, making the development process more efficient and user-friendly.

To use kodular, I signed in to kodular. I didn't had an idea about how to use Kodular. So I referred Fabacadamey 2024 studentAnsu Thomas's documentation.


After creating project a new window opens. Kodular Creator has two main views:

I wanted to add a background image for my app. So i downloaded an, image . From the image icon The image is uploded. The changes were made in the background image option.

I dragged the horizontal arrangement from the layout. From properties panel I aligned it in the center. Then I draged button From user interface, and placed it inside the horizontal arrangement.I named button 1 as "Turn on" and button 2 as "turn off". I also draged Web from connectivity. Components like Buttons, Labels, Text Boxes etc..can be dragged from the Palette to the Viewer. Non-visible components like Bluetooth, Sensors, or Notifiers are avilable in the bottom of the palette. We can customize properties (text, color, size, etc.) using the Properties panel.

Then I switched to blocks tab. The block tab consists of event blocks, in the left panel. Drag event blocks and add logic.I copied the IP address Of XIAO board from the code and pasted it in the block.

I needed to upload the code in xiao Esp32 C6. I used the pcb from electronics production week. To get the code , I used chatgpt. Prompt and result included in the bottom part.

The code is given below

#include <WiFi.h>
#include <WebServer.h>

#define LED_PIN 18  // Define the GPIO pin connected to the LED

// Replace with your actual Wi-Fi network credentials
const char* ssid = "yourSSID";
const char* password = "Yourpassword";

// Create a web server object that listens on port 80
WebServer server(80);

// Handle the root page by sending an HTML page with ON/OFF buttons
void handleRoot() {
  String html = "<html><head><title>ESP32-C6 LED Control</title></head><body>";
  html += "<h1>ESP32-C6 LED Control";
  html += "<p><a href=\"/on\"><button>Turn ON</button></a></p>";
  html += "<p><a href=\"/off\"><button>Turn OFF</button></a></p>";
  html += "</body>";
  server.send(200, "text/html", html); // Send the HTML page to the client
}

// Turn the LED ON and redirect back to the root page
void handleOn() {
  digitalWrite(LED_PIN, HIGH);
  server.sendHeader("Location", "/");
  server.send(303);
}

// Turn the LED OFF and redirect back to the root page
void handleOff() {
  digitalWrite(LED_PIN, LOW);
  server.sendHeader("Location", "/");
  server.send(303);
}

void setup() {
  Serial.begin(115200);               // Start serial communication
  pinMode(LED_PIN, OUTPUT);           // Set the LED pin as output
  digitalWrite(LED_PIN, LOW);         // Initialize LED as OFF

  WiFi.begin(ssid, password);         // Connect to Wi-Fi
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("\nConnected! IP address: ");
  Serial.println(WiFi.localIP());     // Print local IP address

  // Define routes for the server
  server.on("/", handleRoot);
  server.on("/on", handleOn);
  server.on("/off", handleOff);
  
  server.begin();                     // Start the web server
  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient();              // Handle incoming client requests
}

        

I uploaded the code in XIAO ESP32 C6

Next we need to test the app. I downloaded kodular companion app in my phone. Then I clicked the test option. I got a QR code. I scanned the code using mobile app.

The result is shown below

Changing the colour of neopixel using kodular

The pcb board from communication week was used here.

I used chatgpt to get the code and logic. the prompt and result included in the bottom part. The initial setup were done as above.

The code I uploaded on esp32 c6 is given below. In place for ssid and password you need to upload the credinials of your wifi.

#include <WiFi.h>                    // Include Wi-Fi library for ESP32
#include <WebServer.h>              // Include WebServer library to create a web server
#include  <Adafruit_NeoPixel.h>      // Include Adafruit NeoPixel library

#define NEOPIXEL_PIN 18             // βœ… Using GPIO 18 for NeoPixel
#define NUMPIXELS 1                 // Number of NeoPixels (in this case, just 1)

const char* ssid = "SSID";          // πŸ” Replace with your Wi-Fi SSID
const char* password = "PASSWORD";  // πŸ” Replace with your Wi-Fi password

Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);  // Initialize NeoPixel strip
WebServer server(80);              // Create a web server on port 80

// Function to set NeoPixel color
void setColor(uint8_t r, uint8_t g, uint8_t b) {
  pixels.setPixelColor(0, pixels.Color(r, g, b));  // Set color of pixel 0
  pixels.show();                                   // Update the NeoPixel to show new color
}

// HTTP handler to receive RGB values from URL parameters
void handleColor() {
  if (server.hasArg("r") && server.hasArg("g") && server.hasArg("b")) {  // Check if RGB parameters are present
    int r = server.arg("r").toInt();  // Convert red value from string to integer
    int g = server.arg("g").toInt();  // Convert green value
    int b = server.arg("b").toInt();  // Convert blue value
    setColor(r, g, b);                // Set NeoPixel to received RGB values
    server.send(200, "text/plain", "Color changed to R:" + String(r) + " G:" + String(g) + " B:" + String(b));  // Send response
  } else {
    server.send(400, "text/plain", "Missing RGB parameters");  // Send error if any parameter is missing
  }
}

void setup() {
  Serial.begin(115200);        // Start serial communication for debugging
  pixels.begin();              // Initialize NeoPixel library
  pixels.show();               // Turn off all pixels at startup

  WiFi.begin(ssid, password);  // Start Wi-Fi connection
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {  // Wait for Wi-Fi to connect
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nConnected! IP address:");
  Serial.println(WiFi.localIP());  // Print local IP address to access server

  server.on("/color", handleColor);  // Define server route for /color
  server.begin();                    // Start the server
  Serial.println("Web server started");
}

void loop() {
  server.handleClient();  // Continuously handle incoming client requests
}

        

I used vertical arrangement and added buttons.I dragged web from palette. Colour palette was not avilable. So I manually added buttons for each colour.

I tested it in the app.

Creating a gradient in neopixel

As there wasn't any colour palette available, I had to create one. I searched in youtube and find a tutorial. I followed it to connect the blocks. The designer and blocks view are given below.


initialize global color to ""

Declares a global variable color with no value at the start. It will be assigned a real color value (like "255,0,0") later during app interaction.

call Canvas1.GetPixelColor

This function reads the color of the pixel at the location where the user is dragging.

  • x = get current X β†’ the X-coordinate of the touch location
  • y = get current Y β†’ the Y-coordinate of the touch location
  • set Label1.BackgroundColor to <the color>

    This sets the background color of Label1 to match the pixel color from the canvas where the user is dragging.

    call Ball1.MoveTo get current X, get current Y

    This block moves the ball (Ball1) to the current touch position on the canvas.

    get current X / get current Y
    : These give the current touch position (coordinates) on the Canvas.
    call Canvas1.GetPixelColor
    : This block fetches the color at a specific pixel on the Canvas based on the coordinates you give it.
    set global color to ...
    : This saves that fetched color into a global variable named color

  • set Web1.URL to
    – You’re setting the URL that the Web component will call
  • join
    – Combines pieces of text into one complete string (used to form a valid URL).
  • url/setcolor?r=
    – The base URL path to your web server's color endpoint (e.g.,
    http://192.168.1.100/setcolor
    ), followed by the start of a query string for red
    (r=)
    .
  • v
    is a string like "255,100,50" (from
    Canvas.GetPixelColor
    ).
  • split color
    breaks it into a list
    ["255", "100", "50"]
    .
  • select list item list
    with index 1 gets the red component ("255").
  • Same logic applies for
    &g=
    and
    &b=
    with index 2 and 3, for green and blue values.
  • The tutorial didin't showed how to connect it to a board. So I used chatgpt to get the code. The promt and responses are provided in the bottom part of the page. The code is given below.

    #include <WiFi.h>                // Include Wi-Fi library for ESP32
    #include <WebServer.h>          // Include WebServer library to create HTTP server
    #include <Adafruit_NeoPixel.h>  // Include NeoPixel library for controlling RGB LEDs
    
    #define LED_PIN    18              // Define the GPIO pin connected to the NeoPixel
    #define NUM_LEDS   1               // Number of NeoPixel LEDs used
    
    const char* ssid = "SSID";         // Replace with your Wi-Fi SSID
    const char* password = "PASSWORD"; // Replace with your Wi-Fi password
    
    Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); // Initialize NeoPixel
    WebServer server(80);             // Create a web server on port 80
    
    // Root handler: returns a basic text response
    void handleRoot() {
      server.send(200, "text/plain", "ESP32 NeoPixel Color Controller"); // Basic root message
    }
    
    // Color control handler: expects RGB values as query parameters
    void handleSetColor() {
      if (server.hasArg("r") && server.hasArg("g") && server.hasArg("b")) { // Check for RGB arguments
        int r = server.arg("r").toInt();  // Convert 'r' parameter to integer
        int g = server.arg("g").toInt();  // Convert 'g' parameter to integer
        int b = server.arg("b").toInt();  // Convert 'b' parameter to integer
    
        pixels.setPixelColor(0, pixels.Color(r, g, b)); // Set NeoPixel color
        pixels.show(); // Apply the color to the LED
    
        server.send(200, "text/plain", "Color set!"); // Send confirmation
      } else {
        server.send(400, "text/plain", "Missing RGB arguments"); // Send error if parameters are missing
      }
    }
    
    void setup() {
      Serial.begin(115200);       // Start serial communication
      pixels.begin();             // Initialize NeoPixel library
      pixels.show();              // Turn off all pixels initially
    
      WiFi.begin(ssid, password); // Start Wi-Fi connection
      Serial.print("Connecting to Wi-Fi");
    
      while (WiFi.status() != WL_CONNECTED) { // Wait until connected
        delay(500);
        Serial.print(".");
      }
    
      Serial.println("\nConnected to WiFi.");         // Confirm connection
      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());                 // Display IP for access
    
      server.on("/", handleRoot);                     // Define root route
      server.on("/setcolor", handleSetColor);         // Define /setcolor route
      server.begin();                                 // Start the server
      Serial.println("HTTP server started");          // Confirm server is running
    }
    
    void loop() {
      server.handleClient();  // Continuously handle incoming client requests
    }
    
              

    To test the code I opened the Kodular companion app.

    The result is shown below.

    Group assignment

    This week, we explored a variety of tools for creating computer interfaces to better understand how they can be used in our final projects. We worked with Kodular, a visual app builder for Android, to create mobile interfaces without coding. Using PyGame, we developed a simple snake game controlled via a custom macropad. With Processing, we built a visual servo controller using a slider. We also created web-based control interfaces using HTML, CSS, and JavaScript, enabling real-time communication with microcontrollers like the ESP32-S3 over WebSerial for tasks like servo motor control and robot navigation. Lastly, we looked at an advanced Flutter app that interfaces with the Spotify Web API, using an ESP32 to bridge mobile and hardware interaction via HTTP. These tools highlighted different ways to create interactive experiences across mobile, desktop, and web platforms.

    Group assignment page

    Files

    Files

    The chatgpt prompt and responses are given below