정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

FND 7세그먼트를 이용한 스탑워치 만들기 소스에 대해 질문드립니다. ㅠㅠㅠ
박슬기 | 2015-11-27

FND를 이용한 스탑 워치를 만들려고 하는데요 

버튼을 누르고 있을 때 on되고

버튼을 누르고 있지 않을 때 off가 될려면 

아래 소스 코드를 어떻게 수정해야 하나요? 다른 예제들 보면서 수정해

봤는데 잘 모르겠어서 질문드립니다.ㅠㅠㅠ

int aPin = 2;  //  
 int bPin = 3;  //    
 int cPin = 4;  //   
 int dPin = 5;  //    
 int ePin = 6;  //          
 int fPin = 7;  //           
 int gPin = 8;  //      
 int GND1 = 9;  //    
 int GND2 = 10; //   
 int GND3 = 11; //      
 int GND4 = 12; //       
 int num;       //       
 int dig1 = 0;
 int dig2 = 0;
 int dig3 = 0;
 int dig4 = 0;
 int DTime = 4;


 void setup()
 {
   pinMode(aPin, OUTPUT);
   pinMode(bPin, OUTPUT);
   pinMode(cPin, OUTPUT);
   pinMode(dPin, OUTPUT);
   pinMode(ePin, OUTPUT); 
   pinMode(fPin, OUTPUT);
   pinMode(gPin, OUTPUT);
   pinMode(GND1, OUTPUT);
   pinMode(GND2, OUTPUT);
   pinMode(GND3, OUTPUT);
   pinMode(GND4, OUTPUT);
   Serial.begin(9600);
 }
 void loop()
 {
   digitalWrite( GND1, HIGH);
   digitalWrite( GND2, HIGH);
   digitalWrite( GND3, HIGH);
   digitalWrite( GND4, HIGH);

 
 {
   num = millis()/12000;
   Serial.println(num);
   dig1 = num / 1000;
   num = num - (dig1 * 1000);
   dig2 = num / 100;
   num = num - (dig2 * 100);
   dig3 = num / 10;
   dig4 = num - (dig3 *10);
 }
  
  
   digitalWrite( GND4, LOW);    //digit 4
   pickNumber(dig4);
   delay(DTime);
   digitalWrite( GND4, HIGH);
  
   digitalWrite( GND3, LOW);    //digit 3
   pickNumber(dig3);
   delay(DTime);
   digitalWrite( GND3, HIGH);
  
   digitalWrite( GND2, LOW);   //digit 2
   pickNumber(dig2);
   delay(DTime);
   digitalWrite( GND2, HIGH);
  
   digitalWrite( GND1, LOW);   //digit 1
   pickNumber(dig1);
   delay(DTime);
   digitalWrite( GND1, HIGH);

 }
  
 void pickNumber(int x){
    switch(x){
      case 1: one(); break;
      case 2: two(); break;
      case 3: three(); break;
      case 4: four(); break;
      case 5: five(); break;
      case 6: six(); break;
      case 7: seven(); break;
      case 8: eight(); break;
      case 9: nine(); break;
      default: zero(); break;
    }
 }

 void clearLEDs()
 {  
   digitalWrite(  2, LOW); // A
   digitalWrite(  3, LOW); // B
   digitalWrite(  4, LOW); // C
   digitalWrite(  5, LOW); // D
   digitalWrite(  6, LOW); // E
   digitalWrite(  7, LOW); // F
   digitalWrite(  8, LOW); // G
 }

 void one()
 {
   digitalWrite( aPin, LOW);
   digitalWrite( bPin, HIGH);
   digitalWrite( cPin, HIGH);
   digitalWrite( dPin, LOW);
   digitalWrite( ePin, LOW);
   digitalWrite( fPin, LOW);
   digitalWrite( gPin, LOW);
 }

 void two()
 {
   digitalWrite( aPin, HIGH);
   digitalWrite( bPin, HIGH);
   digitalWrite( cPin, LOW);
   digitalWrite( dPin, HIGH);
   digitalWrite( ePin, HIGH);
   digitalWrite( fPin, LOW);
   digitalWrite( gPin, HIGH);
 }

 void three()
 {
   digitalWrite( aPin, HIGH);
   digitalWrite( bPin, HIGH);
   digitalWrite( cPin, HIGH);
   digitalWrite( dPin, HIGH);
   digitalWrite( ePin, LOW);
   digitalWrite( fPin, LOW);
   digitalWrite( gPin, HIGH);
 }

 void four()
 {
   digitalWrite( aPin, LOW);
   digitalWrite( bPin, HIGH);
   digitalWrite( cPin, HIGH);
   digitalWrite( dPin, LOW);
   digitalWrite( ePin, LOW);
   digitalWrite( fPin, HIGH);
   digitalWrite( gPin, HIGH);
 }

 void five()
 {
   digitalWrite( aPin, HIGH);
   digitalWrite( bPin, LOW);
   digitalWrite( cPin, HIGH);
   digitalWrite( dPin, HIGH);
   digitalWrite( ePin, LOW);
   digitalWrite( fPin, HIGH);
   digitalWrite( gPin, HIGH);
 }

 void six()
 {
   digitalWrite( aPin, HIGH);
   digitalWrite( bPin, LOW);
   digitalWrite( cPin, HIGH);
   digitalWrite( dPin, HIGH);
   digitalWrite( ePin, HIGH);
   digitalWrite( fPin, HIGH);
   digitalWrite( gPin, HIGH);
 }

 void seven()
 {
   digitalWrite( aPin, HIGH);
   digitalWrite( bPin, HIGH);
   digitalWrite( cPin, HIGH);
   digitalWrite( dPin, LOW);
   digitalWrite( ePin, LOW);
   digitalWrite( fPin, LOW);
   digitalWrite( gPin, LOW);
 }

 void eight()
 {
   digitalWrite( aPin, HIGH);
   digitalWrite( bPin, HIGH);
   digitalWrite( cPin, HIGH);
   digitalWrite( dPin, HIGH);
   digitalWrite( ePin, HIGH);
   digitalWrite( fPin, HIGH);
   digitalWrite( gPin, HIGH);
 }

 void nine()
 {
   digitalWrite( aPin, HIGH);
   digitalWrite( bPin, HIGH);
   digitalWrite( cPin, HIGH);
   digitalWrite( dPin, HIGH);
   digitalWrite( ePin, LOW);
   digitalWrite( fPin, HIGH);
   digitalWrite( gPin, HIGH);
 }

 void zero()
 {
   digitalWrite( aPin, HIGH);
   digitalWrite( bPin, HIGH);
   digitalWrite( cPin, HIGH);
   digitalWrite( dPin, HIGH);
   digitalWrite( ePin, HIGH);
   digitalWrite( fPin, HIGH);
   digitalWrite( gPin, LOW);
 } 

이전글   |    오렌지보드 BLE 구매시 자료(회로도, 소스코드등)제공 되는지요?... 2015-11-27
다음글   |    아두이노 블루투스 RC카 2015-11-27