logo

Until 24 May 2017

Interface and Application Programming
Processing and Arduino IDE

Contents

- Programming uisng Arduino IDE and Processing
- Programming Input device with Processing

Programming uisng Arduino IDE and Processing

Great reference for this week was Processing website's electronics tutorial and Sparkfun's Connecting Arduino to Processing. I've watched and learned basic codings.

I tried to use 'hello board' to make my interface and application program week, because I had button(input) and LED(output). However, I had problem connecting my mac with USB connectors. I didn't realize my computer was the problem. First, I thought it was my new processing sketch, but I've changed to examples from the website, but it didn't work.


Codes

Processing code
// Read data from the serial port and change the color of a rectangle
// when a switch connected to the board is pressed and released

import processing.serial.*;

Serial port; // Create object from Serial class
int val; // Data received from the serial port

void setup() {
size(600, 400);
frameRate(10);
// Open the port that the board is connected to and use the same speed (9600 bps)
port = new Serial(this, 9600);
}

void draw() {
if (0 < port.available()) { // If data is available,
val = port.read(); // read it and store it in val
}
background(255); // Set background to white
if (val == 0) { // If the serial value is 0,
fill(0); // set fill to black
} else { // If the serial value is not 0,
fill(204); // set fill to light gray
}
rect(50, 50, 100, 100);
}

Arduino IDE code(simple switch)
// Code for sensing a switch status and writing the value to the serial port

int switchPin = 4; // Switch connected to pin 4

void setup() {
pinMode(switchPin, INPUT); // Set pin 0 as an input
Serial.begin(9600); // Start serial communication at 9600 bps
}


void loop() {
if (digitalRead(switchPin) == HIGH) { // If switch is ON,
Serial.write(1); // send 1 to Processing
} else { // If the switch is not ON,
Serial.write(0); // send 0 to Processing
}
delay(100); // Wait 100 milliseconds
}

Arduino IDE code(switch)
// constants won't change. They're used here to
// set pin numbers:
const int switchPin = 3; // the number of the pushbutton pin
const int ledPin = 7; // the number of the LED pin

// variables will change:
int switchState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(switchPin, INPUT);
Serial.begin(9600); // Start serial communication at 9600 bps
}


void loop() {
// read the state of the pushbutton value:
switchState = digitalRead(switchPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (switchState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
if (digitalRead(switchPin) == HIGH) { // If switch is ON,
Serial.write(1); // send 1 to Processing
}

else { // If the switch is not ON,
Serial.write(0); // send 0 to Processing
}
delay(100); // Wait 100 milliseconds
}

Example from Processing website.


After debugging, a melt-down and trying out with arduino with simple arduino sketch. It just didn't register.



Sketch>library>Serial


First I got null. It was because of my computer. So, I've used other computer and got 'hello world' Processing Code & Arduino Code
Sparkfun's 'Connecting Arduino to Processing'

I tried to use Processing app on my android phone to make app using tutorials.

Programming Input device with Processing

The input device used for this assignment is Hello Board with button and LED. Arduino Code and Processing Code


As I press the button in the hello board, the LED from the hello board lights up and red dot on the processing shows.

16th Meeting:
interface and application programming 17 May, 2017 10pm~1am(Seoul)

Homework

o - Implement and interpret networking protocols
o - Described your design and fabrication process of your APPLICATION
o - had fun with visuals!! and buttons,etc
o - Outlined problems and how you fixed them
o - Described your problems and how you fixed
o - included original design files (Eagle, KiCad, Inkscape - whatever)