아두이노프로세싱 프로그래밍

라즈베리 파이 3 에서 프로세싱 코드의 Hardware I/O 라이브러리에 의한 LED ON OFF

coding art 2017. 6. 23. 17:15
728x90


필요한 예제 설명과 절차에 관해서는 최근에 출간 된 종이 책 "라즈베리 와이파이 코딩"을 참고하기 바란다
























































 

.

 















LED_01


import processing.io.*; 

  

 boolean ledStatus = false; 

 int rectX = 50; 

 int rectY = 50; 

 int rectW = 200; 

 int fillCol; 

 

  void setup() { 

   size(300,300); 

   GPIO.pinMode(17,GPIO.OUTPUT);   

    

   background(255        ); 

   stroke(0); 

   strokeWeight(3); 

 } 

 

 

 void draw() { 

   if (ledStatus) { 

     // if led on, fill rectangle light grey 

     fillCol = 200;   

   } else { 

     // if led off, fill rectangle dark grey 

     fillCol = 150;   

   } 

   fill(fillCol); 

    

   // draw the button 

   rect(rectX,rectY,rectW,rectW); 

    

   // turn on/off led 

   GPIO.digitalWrite(17,ledStatus);   

 } 

 

 

 void mouseClicked() { 

   // if mouse pos in button boundary, change led status 

   if (mouseX > rectX && mouseX < rectX + rectW) { 

     if (mouseY > rectY && mouseY < rectY + rectW) { 

       ledStatus = !ledStatus;   

     } 

   } 

 } 

 

 

 void keyPressed() { 

   // if key pressed, quit program 

   GPIO.releasePin(17); 

   exit(); 

 }