• 강의
  • 커뮤니티
  • 북마크
GCR

자료실

코딩자료 | 프로세싱 코드(키패드)

최고관리자
2019.12.09 10:45 61 0

본문

프로세싱 코드


import processing.serial.*;
Serial myPort;

void setup(){
  size(400,400);
  textAlign(CENTER, CENTER);
  randomSeed(second());
  background(255);
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[2], 9600);
}

void draw(){

}

void serialEvent(Serial p){
  char c = p.readChar();
  pushMatrix();
  translate(random(0,width), random(0, height));
  textSize(random(15, 2000));
  fill(random(0,255), random(0,255),
  random(0,255),180);
  rotate(random(0, TWO_PI));
  text(c,0,0);
  popMatrix();
}


========================================================

아두이노 코드​

#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[] = {'1','2','3','A', '4','5','6','B','7','8','9','C','*','0','#','D'};
byte colPins[ROWS] = {5, 4, 3, 2};
byte rowPins[COLS] = {9, 8, 7, 6};
Keypad keypad = Keypad( keys, rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();
  if (key != NO_KEY){
      Serial.print(key);
  }
}​


---------------------------------------------------------------------------------​

참고 코드​

​#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
  {
    {'1','2','3','A'},
    {'4','5','6','B'},
    {'7','8','9','C'},
    {'*','0','#','D'}
  };
byte colPins[ROWS] = {5, 4, 3, 2};
byte rowPins[COLS] = {9, 8, 7, 6};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();
  if (key != NO_KEY){
      Serial.print(key);
  }
}


pushMatrix, popMatrix 참고코드

float theta=0;
void setup(){
 size(400, 400);
}
void draw(){
  background(255);
  stroke(0);
  fill(100);
  rectMode(CENTER);
  translate(width/2, height/2);
  rotate(theta);
  rect(0, 0, 60, 60);
  translate(150, 150);
  rotate(theta);
  rect(0, 0, 60, 60);
  theta += 0.02;
}

----------------------------------------------

​float theta=0;

void setup(){
  size(400, 400);
}

void draw(){
  background(255);
  stroke(0);
  fill(100);
  rectMode(CENTER);
  translate(width/2, height/2); 
  pushMatrix();
  rotate(theta);
  rect(0, 0, 60, 60);
  popMatrix();
  pushMatrix();
  translate(150, 150);
  rotate(theta);
  rect(0, 0, 60, 60);
  popMatrix();
  theta += 0.02;
}

댓글목록 0

등록된 댓글이 없습니다.