Miu Ling Lam

Media Art, Physcial Computing, Interaction Design – a blog connects me to like minds

Arduino Multiplexing Example 1

Processing code:

import processing.serial.*;
Serial myPort;

int numChannels = 16;

void setup() {
  size(1280,800);
//  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  background(0);
}

void draw() {
}

void mouseMoved() {
  int ID = int(map(mouseX,0,width,0,numChannels));
  myPort.write(ID);
}

Arduino code:

// 16 channels
int r0 = 0;
int r1 = 0;
int r2 = 0;
int r3 = 0;
int row = 0;
int ID = 0;
int bin [] = {0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111};

void setup(){
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.begin(115200);
}

void loop () {
  if (Serial.available()) {
    ID = Serial.read();
    Serial.print(ID);
  }
  row = bin[ID];
  r0 = row & 0x01;
  r1 = (row>>1) & 0x01;
  r2 = (row>>2) & 0x01;
  r3 = (ID>7)? 1:0;
  digitalWrite(2, r0);
  digitalWrite(3, r1);
  digitalWrite(4, r2);
  digitalWrite(5, r3);
}
Advertisements

Filed under: Physcial Computing, Programming

Circle Packing is Art

I used Circle Packing in my PhD thesis “Active Sensor Network Deployment for Maximal Coverage” and I always wanted to implement the algorithms in Processing. I finally did it last week. The mathematics behind Circle Packing is just as beautiful as how it looks.

Filed under: Media Art, Programming, , ,

Pages

Archives

November 2017
S M T W T F S
« May    
 1234
567891011
12131415161718
19202122232425
2627282930