16. Interface and Application programming


Assignments

  1. Write an application that interfaces with an input &/or output device that you made,


Designing schematic & board layout

I have decided to make LED ON/OFF based on the mouse hovering on certain rectangular region in interface.

I designed a board having a switch & a led with attiny44.

Here is the schematic & board layout designed in eagle.

Schematic


Board Layout

Milling & Soldering the board

Then I milled the board & soldered it.

Milled Board
Board with components soldered on it

Downloading & installing processing

I decided to use processing for making interface. I downloaded the procesing from here and installed it.

Then I followed the electronics tutorial of processing.


Embedded Programming

Here is the code for attiny44 board.

	#include 
SoftwareSerial mySerial(1,0); // RX, TX
// Read data from the serial and turn ON or OFF a light depending on the value
 
char val;                          // Data received from the serial port 
int ledPin = 7;                    // Set the pin to digital I/O 4

void setup() { 
  pinMode(ledPin, OUTPUT);  // Set pin as OUTPUT 
  mySerial.begin(9600);              // Start serial communication at 9600 bps 
} 


void loop() { 
  if (mySerial.available()) {        // If data is available to read, 
    val = mySerial.read();  // read it and store it in val 
  } 
  if (val == '1') {                // If H was received
    digitalWrite(ledPin, HIGH);    // turn the LED on 
  } else if(val== '0') { 
    digitalWrite(ledPin, LOW);     // Otherwise turn it OFF
  } 
  delay(100);    // Wait 100 milliseconds for next reading 
} 
	

Processing Code

Here is the code in processing for creating a GUI which includes a rectangular block. This rectangular block turns gray on mouse hovering and turns black otherwise.

	// Check if the mouse is over a rectangle and write the status to the serial port

import processing.serial.*; 
 
Serial port;                       // Create object from Serial class
 
void setup() { 
  size(200, 200); 
  noStroke(); 
  frameRate(10); 
  println(Serial.list());
  // Open the port that the board is connected to and use the same speed (9600 bps)
  port = new Serial(this,Serial.list()[0], 9600); 
} 
 
void draw() { 
  background(255); 
  if (mouseOverRect() == true)  {  // If mouse is over square,
    fill(204);                     // change color and  
    port.write('1');               // send an H to indicate mouse is over square 
  } else {                         // If mouse is not over square,
    fill(0);                       // change color and
    port.write('0');               // send an L otherwise
  } 
  rect(50, 50, 100, 100);          // Draw a square 
} 


boolean mouseOverRect() {        // Test if mouse is over square 
  return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150)); 
} 
	

Output Video

Here is the output...


You can download files here...