이메일

구글 : kdj777ehdwns@gmail.com
네이버 : kdj777ehdwns@naver.com
epsckr2016.blogspot.com

2016년 9월 29일 목요일

NumBaseball 0단계,1단계

import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
public class NumBaseball extends Frame implements ActionListener{
 Label disp;
 TextArea rec;
 Panel numPanel;
 Button[] btns = new Button[ 12 ];
 int[] com = new int[ 3 ];
 int[] usr = new int[ 3 ];
 int cnt, scnt, bcnt;
 boolean gameover;
 int a=0;  

 public static void main(String[] args) {
  NumBaseball f = new NumBaseball ( "숫자야구 Ver 1.0");
  f.setSize( 500,500 );
  f.setVisible( true );
 }
 public NumBaseball( String title) {
  super( title );

  disp = new Label();
  disp.setAlignment( Label.RIGHT );
  add( "North", disp );

  numPanel = new Panel();
  numPanel.setLayout( new GridLayout( 4,3 ) );
  for( int i = 7; i > 0; i -= 3 ) {
   for( int j = 0; j < 3; j++ ) {
    btns[ i + j ] = new Button( String.valueOf( i + j ));
    numPanel.add( btns[ i + j ] );
   }
  }
  btns [ 0 ] = new Button( "←" );
  numPanel.add( btns[ 0 ]);
  btns [ 10 ] = new Button( "다시" );
  numPanel.add( btns[ 10 ]);
  btns [ 11 ] = new Button( "완료" );
  numPanel.add( btns[ 11 ]);
  add( "Center", numPanel );

  rec = new TextArea( 10,20 );
  add( "South", rec );

  for( int i = 0; i < 12; i++ ) {
   btns[ i ].addActionListener( this );
  }

  Random r = new Random();
  com[ 0 ] = Math.abs(r.nextInt() % 9 ) + 1;
  do {
   com[ 1 ] = Math.abs(r.nextInt() % 9 ) + 1;
  } while( com[ 0 ] == com[ 1 ] );
  do {
   com[ 2 ] = Math.abs(r.nextInt() % 9 ) + 1;
  } while( com[0] == com[2] || com[1]==com[2] );
      
  cnt = 0; scnt = 0; bcnt = 0;
  gameover = false;
 }

    public void actionPerformed( ActionEvent e ) {
     if ( gameover ) return;
   
     if( e.getSource() == btns [ 0 ] ) {
      // ← 버튼 눌렀을때
      if( cnt > 0 ) {
       cnt--;
       disp.setText( "" );
       for( int i = 0; i < cnt; i++ ) {
        disp.setText( disp.getText() + usr[ i ] );
       }
      }
     } else if( e.getSource() == btns[ 10 ] ) {
      // 다시 버튼을 눌렀을 때
      disp.setText( "" );
      usr[ 0 ] = usr[ 1 ] = usr[ 2 ] = 0;
      cnt = 0;
   
     } else if( e.getSource() == btns[ 11 ] ) {
      // 완료 버튼을 눌렀을 때
      if( cnt ==3 ) {
       scnt = 0; bcnt = 0;
       if( usr[ 0 ] == com[ 0 ] ) scnt++;
       if( usr[ 1 ] == com[ 1 ] ) scnt++;
       if( usr[ 2 ] == com[ 2 ] ) scnt++;
   
       if( usr[ 0 ] == com[ 1 ] ) bcnt++;
       if( usr[ 0 ] == com[ 2 ] ) bcnt++;
       if( usr[ 1 ] == com[ 0 ] ) bcnt++;
       if( usr[ 1 ] == com[ 2 ] ) bcnt++;
       if( usr[ 2 ] == com[ 0 ] ) bcnt++;
       if( usr[ 2 ] == com[ 1 ] ) bcnt++;
   
       rec.append( usr[0] + "" + usr[1] + "" +
              usr[2] + "  → " +
                   scnt + "S"+bcnt + "B\n");
       a++; 
                cnt = 0;
                usr[ 0 ] = usr[ 1 ] = usr[ 2 ] = 0;
                disp.setText( "" );
               
                if( scnt == 3 ) {
                 //3개의 숫자를 다 맞추었을 때
                 gameover = true;
                 disp.setText("Game Over!!!");
                 rec.append( a+"번만에 맞추셨습니다"+"축하합니다.\n" );
                              
                }
      }
     } else {
      // 숫자 버튼을 눌렀을 때
      if( cnt < 3 ) {
       char btnVal = ((Button)e.getSource())
                  .getLabel().charAt( 0 );
       usr[ cnt ] = Integer.valueOf(
         String.valueOf( btnVal )).intValue();
       disp.setText(disp.getText() + btnVal );
       cnt++;
      }
     }
    }
}






날짜 : 2016년 09월 29일

[아두이노] 초음파 센서로 거리 측정하기

 
 
int trigPin = 9;
int echoPin = 8;
void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}
void loop() {
  float duration, distance;
  digitalWrite(trigPin, HIGH);
  delay(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = ((float)(340 * duration) / 10000) / 2;
 
  Serial.print("Duration:");
  Serial.print(duration);
  Serial.print(" \nDuration:");
  Serial.print(distance);
  Serial.print("cm \n");
  delay(500);
}
 
 


날짜 : 2016년 09월 29일

[아두이노] 초음파 센서로 LED 제어하기

 
#define TRIG_PIN 2
#define ECHO_PIN 3
#define LED_PIN 4
void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
}
void loop()
{
  int distance = 0;
 
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  distance = pulseIn(ECHO_PIN, HIGH)/58.2;
 
  if (distance <= 10) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }
}
 
 



날짜 : 22016년 09월 29일

2016년 9월 27일 화요일

[이클립스] 가위바위보 수행평가

가위바위보+10번누르면전적+x누르면닫기


import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class srpgame extends Frame implements ActionListener {
 Button scissors, rock, paper, end;
 Image img1, img2, img3;
 int usr, com;
 boolean win, tie, lose;
 int cnt, cwin, close, ctie;  //cnt=전체횟수, cwin=이긴횟수 close=진횟수 ctie=비긴횟수

 public static void main(String[] args) {
  srpgame f = new srpgame( "가위바위보 Ver 1.0" );
  f.setSize( 500, 500 );
  f.setVisible( true );
 }

 public srpgame( String title ) {
  super( title );
  setLayout( new FlowLayout() );
  scissors = new Button( "가위" );
  rock = new Button( "바위" );
  paper = new Button( " 보 " );
  end  = new Button( "종료" );
  add( scissors ); add( rock);
  add( paper );  add( end );
  scissors.addActionListener( this );
  rock.addActionListener( this);
  paper.addActionListener( this);
  end.addActionListener( this );
  img1 = Toolkit.getDefaultToolkit()
  .getImage( "C:\\Users\\user\\workspace\\RPSgame\\src\\image\\img1.png" );
  img2 = Toolkit.getDefaultToolkit()
  .getImage( "C:\\Users\\user\\workspace\\RPSgame\\src\\image\\img2.png" );
  img3 = Toolkit.getDefaultToolkit()
  .getImage( "C:\\Users\\user\\workspace\\RPSgame\\src\\image\\img3.png" );
  usr = 0; com = -1;
  cnt = 0; cwin = 0; close = 0; ctie = 0; // 초기화
 }

 public void actionPerformed( ActionEvent  e ) {
  cnt++; //누른횟수 기억,누를때마다 증가
  if( e.getSource() == end ) System.exit( 0 );
  if( e.getSource() == scissors ) usr = 1;
  if( e.getSource() == rock ) usr = 2;
  if( e.getSource() == paper ) usr = 3;
  com = ( int ) ( Math.random() * 3 ) + 1;
  repaint();
 }


 public void paint( Graphics g ) {
  g.drawImage(img1, 100, 100, 100, 100, this );
  g.drawImage(img2, 200, 100, 100, 100, this );
  g.drawImage(img3, 300, 100, 100, 100, this );
  win=false; lose=false; tie=false;
  switch( usr ) {
  case 1: g.drawImage(img1, 100, 250, 100, 100, this ); break;
  case 2: g.drawImage(img2, 100, 250, 100, 100, this ); break;
  case 3: g.drawImage(img3, 100, 250, 100, 100, this ); break;
  default: g.drawString("", 100, 250 );
  }
  switch( com ) {
  case 1: g.drawImage(img1, 300, 250, 100, 100, this ); break;
  case 2: g.drawImage(img2, 300, 250, 100, 100, this ); break;
  case 3: g.drawImage(img3, 300, 250, 100, 100, this ); break;
  default: g.drawString("", 300, 250 );
  }
  if ( usr == com ) tie = true;
  else if( usr == 1 && com == 2 ) lose = true;
  else if( usr == 1 && com == 3 ) win = true;
  else if( usr == 2 && com == 1 ) win = true;
  else if( usr == 2 && com == 3 ) lose = true;
  else if( usr == 3 && com == 1 ) lose = true;
  else if( usr == 3 && com == 2 ) win = true;
  if( tie ) {
 g.drawString( "비김", 200, 400 );
      ctie++;
  }
  else if( win ) {
 g.drawString( "승리", 200, 400);
      cwin++;
  }
  else if( lose ) {
 g.drawString( "패배", 200, 400);
      close++;
  }
  if( cnt == 10 ) {
 g.drawString( cwin+"승, "+close+"패, "+ctie+"무", 300,400 );
  } addWindowListener( new java.awt.event.WindowAdapter() {
  public void windowClosing( java.awt.event.WindowEvent e ) {
System.exit( 0 );
}
});
 }
}


날짜 : 2016년 09월 27일

[이클립스] 가위바위보

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class srpgame extends Frame implements ActionListener {
 Button scissors, rock, paper, end;
 Image img1, img2, img3;
 int usr, com;
 boolean win, tie, lose;
 public static void main(String[] args) {
  srpgame f = new srpgame( "가위바위보 Ver 1.0" );
  f.setSize( 500, 500 );
  f.setVisible( true );
 }

 public srpgame( String title ) {
  super( title );
  setLayout( new FlowLayout() );
  scissors = new Button( "가위" );
  rock = new Button( "바위" );
  paper = new Button( " 보 " );
  end  = new Button( "종료" );
  add( scissors ); add( rock);
  add( paper );  add( end );
  scissors.addActionListener( this );
  rock.addActionListener( this);
  paper.addActionListener( this);
  end.addActionListener( this );
  img1 = Toolkit.getDefaultToolkit()
  .getImage( "C:\\Users\\user\\workspace\\SRP\\src\\image\\img1.png" );
  img2 = Toolkit.getDefaultToolkit()
  .getImage( "C:\\Users\\user\\workspace\\SRP\\src\\image\\img2.png" );
  img3 = Toolkit.getDefaultToolkit()
  .getImage( "C:\\Users\\user\\workspace\\SRP\\src\\image\\img3.png" );
  usr = 0; com = -1;
 }
 public void actionPerformed( ActionEvent  e ) {
  if( e.getSource() == end ) System.exit( 0 );
  if( e.getSource() == scissors ) usr = 1;
  if( e.getSource() == rock ) usr = 2;
  if( e.getSource() == paper ) usr = 3;
  com = ( int ) ( Math.random() * 3 ) + 1;
  repaint();
 }
 public void paint( Graphics g ) {
  g.drawImage(img1, 100, 100, 100, 100, this );
  g.drawImage(img2, 200, 100, 100, 100, this );
  g.drawImage(img3, 300, 100, 100, 100, this );
  win=false; lose=false; tie=false;
  switch( usr ) {
  case 1: g.drawImage(img1, 100, 250, 100, 100, this ); break;
  case 2: g.drawImage(img2, 100, 250, 100, 100, this ); break;
  case 3: g.drawImage(img3, 100, 250, 100, 100, this ); break;
  default: g.drawString("", 100, 250 );
  }
  switch( com ) {
  case 1: g.drawImage(img1, 300, 250, 100, 100, this ); break;
  case 2: g.drawImage(img2, 300, 250, 100, 100, this ); break;
  case 3: g.drawImage(img3, 300, 250, 100, 100, this ); break;
  default: g.drawString("", 300, 250 );
  }
  if ( usr == com ) tie = true;
  else if( usr == 1 && com == 2 ) lose = true;
  else if( usr == 1 && com == 3 ) win = true;
  else if( usr == 2 && com == 1 ) win = true;
  else if( usr == 2 && com == 3 ) lose = true;
  else if( usr == 3 && com == 1 ) lose = true;
  else if( usr == 3 && com == 2 ) win = true;
  if( tie ) g.drawString( "비김", 200, 400 );
  else if( win ) g.drawString( "승리", 200, 400);
  else if( lose ) g.drawString( "패배", 200, 400);
 }
}


날짜 : 2016년 09월 27일

2016년 9월 22일 목요일

[이클립스] 버튼과 레이블

버튼 예제
import java.awt.Button;
 import java.awt.Color;
 import java.awt.Frame;

 public class FrameTest extends Frame {

 // 생성자
 public FrameTest( String str ) {
  super( str );
 }

 public static void main(String[] args) {
  FrameTest fr = new FrameTest( "컴퓨터정보과" );
  Button btn2 = new Button();
  btn2.setLabel( "North" );
  btn2.setBackground( Color.blue );
  fr.add( btn2, "North" );
  Button btn1 = new Button();
  btn1.setLabel( "Center" );
  btn1.setBackground( Color.cyan );
  fr.add( btn1, "Center" );
  Button btn3 = new Button();
  btn3.setLabel( "West" );
  btn3.setBackground( Color.green );
  fr.add( btn3, "West" );
  Button btn4 = new Button();
  btn4.setLabel( "East" );
  btn4.setBackground( Color.orange );
  btn4.setEnabled( false );
  fr.add( btn4, "East" );
  Button btn5 = new Button();
  btn5.setLabel( "South" );
  btn5.setBackground( Color.yellow );
  fr.add( btn5, "South" );
  fr.setSize( 500, 500 );
  fr.setBackground( Color.GREEN );
  fr.setVisible( true );
 }

 }



버튼 테스트 예제

import java.awt.Button;
 import java.awt.Color;
 import java.awt.FlowLayout;
 import java.awt.Frame;
 import java.awt.Label;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;

 public class LabelTest extends Frame implements ActionListener {
 Label lbl1, lbl2, lbl3;
 Button btn;

 public static void main(String[] args) {
  LabelTest lbltest = new LabelTest( "위대한 프로그램" );
  lbltest.setSize( 500, 500 );
  lbltest.setBackground( Color.yellow );
  lbltest.setVisible( true );
 }

 public LabelTest( String title ) {
  super( title );
  setLayout( new FlowLayout() );
  lbl1 = new Label(); lbl1.setText( "은평문화예술정보학교" );
  lbl1.setAlignment( Label.LEFT ); lbl1.setBackground( Color.cyan );
  add( lbl1 );
  lbl2 = new Label(); lbl2.setText( "컴퓨터정보" );
  lbl2.setAlignment( Label.CENTER );
  add( lbl2 );
  lbl3 = new Label(); lbl3.setText( "이세진" );
  lbl3.setAlignment( Label.RIGHT ); lbl3.setBackground( Color.blue );
  add( lbl3 );
  btn = new Button( "종료" );
  btn.addActionListener( this );
  add( btn );
 }

 public void actionPerformed( ActionEvent e ) {
  if( e.getSource() == btn ) {
   System.exit( 0 );
  }
 }

 }



버튼과 레이블 예제

import java.awt.Button;
 import java.awt.Color;
 import java.awt.FlowLayout;
 import java.awt.Frame;
 import java.awt.Label;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;

 public class ButtonLabelTest extends Frame implements ActionListener {
    Button btn1, btn2, btn3, btn4;
    Label label;

    public static void main( String args[] ) {
       ButtonLabelTest fr = new ButtonLabelTest( "컴퓨터정보과" );

       fr.setSize( 500, 500 );
       fr.setBackground( Color.blue );
       fr.setVisible( true );
    }

    public ButtonLabelTest( String str ) {
       super( str );

       setLayout( new FlowLayout() );

       btn1 = new Button( "C언어" );
       btn1.setBackground( Color.cyan );
       btn1.addActionListener( this );

       btn2 = new Button( "자바" );
       btn2.setBackground( Color.yellow );
       btn2.addActionListener( this );

       btn3 = new Button( "Python" );
       btn3.setBackground( Color.green );
       btn3.addActionListener( this );

       label = new Label();
       label.setText( "버튼을 누르시오." );
       label.setAlignment( Label.CENTER );
       label.setBackground( Color.white );

       btn4 = new Button( "종료" );
       btn4.addActionListener( this );

       add( btn1 );
       add( btn2 );
       add( btn3 );
       add( label );
       add( btn4 );
    }

    public void actionPerformed( ActionEvent e ) {
       if( e.getSource() == btn1 ) {
          label.setText( "C언어 선택" );
       }
       if( e.getSource() == btn2 ) {
          label.setText( "자바 선택" );
       }
       if( e.getSource() == btn3 ) {
          label.setText( "Python 선택" );
       }
       if( e.getSource() == btn4 ) {
          System.exit( 0 );
       }
    }
 }




날짜 : 2016년 09월 22일




[아두이노] 센서 가려서 소리 작아지게 하기

 
 
int ledpin=13;
int sensorpin=A0;
void setup()
{
  Serial.begin(9600);
  pinMode(ledpin, OUTPUT);
}
void loop()
{
  int rate = analogRead(sensorpin);
  int pitch = map(rate, 10, 200, 0, 255);
  Serial.println(pitch);
  tone(13,pitch,0);
  delay(100);
}

 
 



날짜: 2016년 09월 22일

[아두이노] 센서 가려서 LED 켜기



int ledpin=13;
int sensorpin=A0;

void setup()
{
  Serial.begin(9600);
  pinMode(ledpin, OUTPUT);
}

void loop()
{
  int rate = analogRead(sensorpin);
  Serial.println(rate);
  
  if (rate > 150)
  {
    digitalWrite(ledpin, LOW);
  }
  else
  {
    digitalWrite(ledpin, HIGH);
    delay(100);
  }
}







날짜 : 2016년09월22

[아두이노] 빛에따라 도,레,미,파,솔,라,시,도 출력



#define NOTE_C4 262 
#define NOTE_D4 294 
#define NOTE_E4 330 
#define NOTE_F4 349 
#define NOTE_G4 392 
#define NOTE_A4 440 
#define NOTE_B4 494
#define NOTE_C5 523 

int speakerSensor=8;
int noteDuration=100;

int cdsPin=0;
int cdsValue=0;
int noteValue=0;

void setup() {
  pinMode(speakerSensor, OUTPUT);
  Serial.begin(9600);
}


void loop() {
  cdsValue=analogRead(cdsPin);
  
  if(cdsValue<40)
  {
    noteValue=NOTE_C4;
  } else if(cdsValue>40 && cdsValue<65){
    noteValue=NOTE_D4;
  } else if(cdsValue>65 && cdsValue<90){
    noteValue=NOTE_E4;
  } else if(cdsValue>90 && cdsValue<115){
    noteValue=NOTE_F4;
  } else if(cdsValue>115 && cdsValue<140){
    noteValue=NOTE_G4;
  } else if(cdsValue>140 && cdsValue<165){
    noteValue=NOTE_A4;
  } else if(cdsValue>165 && cdsValue<190){
    noteValue=NOTE_B4;
  } else if(cdsValue<190){
     noteValue=NOTE_C5;
  }
       
  
    Serial.println(cdsValue);
    tone(speakerSensor, noteValue, noteDuration);
    delay(100);
    }


날짜 : 2016년 9월 22일

2016년 9월 20일 화요일

[아두이노] 버튼을 누르면 도,레,미,파,솔,라,시,도 출력 + 학교종 연주하기

도레미파솔라시도



#define NOTE_C4 262 
#define NOTE_D4 294 
#define NOTE_E4 330 
#define NOTE_F4 349 
#define NOTE_G4 392 
#define NOTE_A4 440 
#define NOTE_B4 494
#define NOTE_C5 523 

int pin[]={2,3,4,5,6,7,8,9};
int note[]={NOTE_C5,NOTE_B4,NOTE_A4,NOTE_G4,NOTE_F4,NOTE_E4,NOTE_D4,NOTE_C4};

void setup() {
  for(int i=0;i<8;++i){
    pinMode(pin[i],INPUT);
  }
}

void loop() {
  for(int i=0;i<8;++i){
    if(digitalRead(pin[i])==HIGH){
      tone(11,note[i],50);
    }
  }
}





학교종 



 #include "pitches.h"

#define TOTAL_SOUND 24
#define SPEAKER_PIN 8

int melody[TOTAL_SOUND] = {
  NOTE_G4, NOTE_G4, NOTE_A5,
  NOTE_A5, NOTE_G4, NOTE_G4,
  NOTE_E4, NOTE_G4, NOTE_G4,
  NOTE_E4, NOTE_E4, NOTE_D4,
  NOTE_G4, NOTE_G4, NOTE_A5,
  NOTE_A5, NOTE_G4, NOTE_G4,
  NOTE_E4, NOTE_G4, NOTE_E4,
  NOTE_D4, NOTE_E4, NOTE_C4
};
  
  
int melody_length[TOTAL_SOUND] = {
  1,1,1,1,1,1,2,1,1,1,1,3,1,1,1,1,1,2,1,1,1,1,1};

void setup() {

  for (int i = 0; i < TOTAL_SOUND; ++i) {
    int duration = 250 * melody_length[i];
    tone(SPEAKER_PIN, melody[i], duration);
    
    int pause = duration * 1.30;
    delay(pause);
    noTone(SPEAKER_PIN);
  }
}

void loop() {

}








날짜: 2016년 09월 20일

[아두이노] 버튼을 누르면 도,레,미 출력



#define NOTE_C4 262 
#define NOTE_D4 294 
#define NOTE_E4 330 

int pin[]={2,3,4};
int note[]={NOTE_E4,NOTE_D4,NOTE_C4};

void setup() {
  for(int i=0;i<3;++i){
    pinMode(pin[i],INPUT);
  }
}

void loop() {
  for(int i=0;i<3;++i){
    if(digitalRead(pin[i])==HIGH){
      tone(8,note[i],20);
    }
  }
}





날짜:  2016년 09월 20일

2016년 9월 13일 화요일

[이클립스] 이미지테스트& ⅹ누르면 창닫기

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

public class imageTest extends Frame {
   Image img1;
 
public static void main(String[] args) {
  imageTest f = new imageTest( "이미지 예제" );
  f.setSize( 500,500 );
  f.setBackground( Color.yellow );
  f.setVisible( true );
}

public imageTest( String s ) {
super( s );
setLayout( new FlowLayout() );
img1 =Toolkit.getDefaultToolkit()
.getImage( "C:\\Users\\user\\workspace\\TextFieldTest\\src\\images\\epsckr.png" );
        addWindowListener( new java.awt.event.WindowAdapter() {
        public void windowClosing( java.awt.event.WindowEvent e ) {
        System.exit( 0 );    // X버튼누르면 창닫기
        }
        });
    }


public void paint( Graphics g ) {
super.paint( g );
g.drawImage( img1, 10, 50, this);
}
}


날짜 : 2016년 09월 13일

[이클립스] 자바의 기본형태

import java.awt.Color;
import java.awt.Frame;
import java.awt.Image;

public class ImageTest extends Frame {
   Image img1;
 
public static void main(String[] args) {
  ImageTest f = new ImageTest( "이미지 예제" );
  f.setSize( 500,500 );
  f.setBackground( Color.yellow );
  f.setVisible( true );
}

public ImageTest( String s ) {
super( s );
    }

}


날짜 : 2016년 09월 13일

2016년 9월 6일 화요일

[아두이노] 버튼을 이용하여 삼색 LED 켜기



#define RED 11
#define GREEN 10
#define BLUE 9
#define RED_BT 4
#define GREEN_BT 3
#define BLUE_BT 2
int r=0, g=0, b=0;

void setup() {
  pinMode(RED_BT,INPUT);
  pinMode(GREEN_BT,INPUT);
  pinMode(BLUE_BT,INPUT);
}
  
  void loop() {
    if(digitalRead(RED_BT)==HIGH){
      ++r;
      if(r>255){
        r=0;
      }
    }
    if(digitalRead(GREEN_BT)==HIGH){
      ++g;
      if(g>255){
        g=0;
      }
    }
    if(digitalRead(BLUE_BT)==HIGH){
      ++b;
      if(b>255){
        b=0;
      }
    }
    
    analogWrite(RED,r);
    analogWrite(GREEN,g);
    analogWrite(BLUE,b);
    delay(10);
}










날짜 : 2016년 09월 06일

2016년 9월 1일 목요일

[아두이노] 삼색 LED 켜기


int Rpin = 9;
int Gpin = 10;
int Bpin = 11;

void setup() {
  pinMode(Rpin, OUTPUT);
  pinMode(Gpin, OUTPUT);
  pinMode(Bpin, OUTPUT);
}

void loop() {
analogWrite(Rpin, 255);
analogWrite(Gpin, 0);
analogWrite(Bpin, 0);
delay(500);
analogWrite(Rpin, 0);
analogWrite(Gpin, 255);
analogWrite(Bpin, 0);
delay(500);
analogWrite(Rpin, 0);
analogWrite(Gpin, 0);
analogWrite(Bpin, 255);
delay(500);

}





날짜: 2016년 09월 01일

[아두이노] 신호등 만들기



#define RED_LED 4
#define YELLOW_LED 3
#define GREEN_LED 2

void setup () {                 
  pinMode(RED_LED, OUTPUT);
  pinMode(YELLOW_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  digitalWrite(RED_LED, HIGH);
}



void loop () {
  delay(3000);
  digitalWrite(RED_LED, LOW); digitalWrite(YELLOW_LED, HIGH);

  delay(3000);
  digitalWrite(YELLOW_LED, LOW); digitalWrite(GREEN_LED, HIGH);

  delay(3000);
  digitalWrite(GREEN_LED, LOW); digitalWrite(RED_LED, HIGH);





날짜: 2016년 09월 01일