개발/Arduino

[Arduino] 프로세싱으로 가변저항 값 출력하기

Hyunsun 2021. 11. 19. 14:42
728x90

프로세싱이란?

컴퓨터 프로그래밍의 본질을 시각적 개념으로 프로그래머가 아닌 사람들에게 교육할 목적으로 뉴 미디어 아트, 시각 디자인 공동체를 위해 개발된 오픈 소스 프로그래밍 언어이자 통합 개발 환경이다.

 

프로세싱 설치

 

Welcome to Processing!

Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts…

processing.org

 

아두이노 연결 방법

(가변저항을 못찾아서 다른 센서 넣음)

 

포트 설정

아두이노 시리얼 포트랑 프로세싱이랑 맞추기

 

프로세싱 글꼴 설정

형광펜 칠한 부분, 사이즈를 맞춰줘야함

 

코드

아두이노 

const int POT = 0;
int val = 0;

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

void loop()
{
  val = analogRead(POT);
  Serial.println(val);
}

 

프로세싱

import processing.serial.*;
Serial port;
PFont font;
String data= "";

void setup()
{
  size(400, 400);
  port=new Serial(this, "COM4", 9600);
  port.bufferUntil('\n');
  font=loadFont("Arial-BoldMT-40.vlw");
  textFont(font, 40);
}
void draw()
{
  background(0, 0, 0);
  fill(220, 50, 220);
  text("val = " +data, 100, 200);
}
void serialEvent(Serial port)
{
  data=port.readStringUntil('\n');
  data=data.substring(0, data.length()-1);
}

 

결과

 

 

728x90