14. Interface and application programming¶
Weekly Summary¶
- Connect Arduino and Processing
Assignments¶
- group assignment
- compare as many tool options as possible
- individual assignment
- write an application that interfaces a user with an input &/or output device that you made
Group Assignment Link¶
Kamakura Group Assignment Week14
Individual Assignment¶
I researched a light on and off with Analog pin on Arduino.
Here is the website that I followed. (Japanese only)
Connecting an Arduino and LED.
Arduino 5V and LED +, Arduino ~9 pin and LED -.
This is the code.
// led_brightness_sample1
const int led_pin = 9;
void setup() {
}
void loop() {
for ( int led_value = 0; led_value < 256; led_value += 10 ) {
analogWrite( led_pin, led_value );
delay( 30 );
}
for ( int led_value = 255; led_value > -1; led_value -= 10 ) {
analogWrite( led_pin, led_value );
delay( 30 );
}
}
I added as follow in “void setup”
Serial. begin(9600);
and as follow in the end of “void loop”
Serial.println(led_value );
It is whole code as follow;
const int led_pin = 0;
void setup() {
Serial. begin(9600);
}
void loop() {
for ( int led_value = 0; led_value < 256; led_value += 10 ) {
analogWrite( led_pin, led_value );
delay( 30 );
}
for ( int led_value = 255; led_value > -1; led_value -= 10 ) {
analogWrite( led_pin, led_value );
delay( 30 );
Serial.println(led_value );
}
}
Simply light on and off as analog way
let’s see with Processing graphics.
import processing.serial.*;
Serial mySerial;
String myString = null;
int nl = 10;
float myVal;
void setup(){
size(200,400);
mySerial = new Serial(this, "COM19", 9600); //type your port name in the middle
}
void draw(){
while (mySerial. available() > 0) {
myString = mySerial.readStringUntil(nl);
if (myString != null){
background(150,10,0); //change the color
myVal = float(myString);
myVal = myVal/200* height;
rectMode(CENTER);
rect(width/2, height-(myVal/2), 100, myVal);
}
}
}
You can see the white rectangle in the middle
I reconnected my PCB next.
I road the code with UPDI, and change to connect with UART for serial monitor.
Nose PCB
// led_light
const int led_pin = 0;
void setup() {
Serial. begin(9600);
}
void loop() {
for ( int led_value = 0; led_value < 256; led_value += 10 ) {
analogWrite( led_pin, led_value );
delay( 100 );
}
for ( int led_value = 255; led_value > -1; led_value -= 10 ) {
analogWrite( led_pin, led_value );
delay( 100 );
Serial.println(led_value);
}
}
Processing
import processing.serial.*;
Serial mySerial;
String myString = null;
int nl = 10;
float myVal;
void setup(){
size(200,400);
mySerial = new Serial(this, "COM15", 9600); //type your port name in the middle
}
void draw(){
while (mySerial. available() > 0) {
myString = mySerial.readStringUntil(nl);
if (myString != null){
background(150,10,0); //change the color
myVal = float(myString);
myVal = myVal/200* height;
rectMode(CENTER);
rect(width/2, height-(myVal/2), 100, myVal);
}
}
}
I can see the value with graphic.
Links¶
What I learned¶
I learn I can connect Arduino IDE and Processing. and a little bit about programming in processing.
I am interested to create generative art. so I tried to keep learning about it.