MUstar

IoT 아두이노 0628 - FND EX_HD1

Jul 1st, 2017
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <MsTimer2.h>
  2.  
  3. int sw[5] ={2,3,4,5,6};
  4. int LED[8] = {22, 24, 26, 28, 30, 32, 34, 36};
  5. int pin_FND_DATA[8] = {23, 25, 27, 29, 31, 33, 35, 37};
  6. int pin_FND_SELECT[6] = {39, 41, 43, 45, 47, 49};
  7. //uint8_t FND_data[16] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x27, 0x7F, 0x6F,0x77, 0x7C, 0x39, 0x5E, 0x79, 0x1};
  8. uint8_t FND_data[16] = {63,6,91,79,102,109,125,39,127,111,119,124,57,94,121,1};
  9. uint8_t data_Cipher[6] = {9,0,9,0,9,0};
  10.  
  11. void setup()
  12. {
  13.   int i;
  14.   for(i=0; i<8; i++)
  15.   {
  16.     pinMode(LED[i],OUTPUT);
  17.     digitalWrite(LED[i], LOW);
  18.   }
  19.   for(i=0; i<5; i++)
  20.     pinMode(sw[i],INPUT_PULLUP);
  21.   for(i=0; i<8; i++)
  22.     pinMode(pin_FND_DATA[i], OUTPUT);
  23.   for(i=0; i<6; i++)
  24.     pinMode(pin_FND_SELECT[i], OUTPUT);
  25.   FND_select(0x3F);
  26.   MsTimer2::set(2, FND_ISR);
  27.   MsTimer2::start();
  28. }
  29.  
  30. void loop()
  31. {
  32.   long sec = 0, temp_num; //int로 선언하면 대략 4만이후로 값이 이상하게 출력
  33.   int stc=0, str=0, stl=1;
  34.   int  cntled, sv_cntled; //컨트롤용 변수
  35.   if (digitalRead(sw[4]) == HIGH) {clear(); delay(1000);}
  36.   if (digitalRead(sw[3]) == HIGH)
  37.   {
  38.     while(1)
  39.     {
  40.       if (digitalRead(sw[2]) == HIGH) {str=1; stc=1; delay(1000);}
  41.       if (digitalRead(sw[3]) == HIGH) {str=0; stc=0; delay(1000);}
  42.       if (digitalRead(sw[4]) == HIGH) {clear(); stl=256; stc=0; sec=0; delay(1000);}
  43.  
  44.       //led_cnt(&stl,str);
  45.       if(stc==1)
  46.       {
  47.         LED_control(0);
  48.         continue;
  49.       }
  50.       else if(stc==0)
  51.       {
  52.         sec++; //Timer Num
  53.         temp_num = sec; data_Cipher[0] = sec/100000;
  54.         temp_num = temp_num%100000; data_Cipher[1] = temp_num/10000;
  55.         temp_num = temp_num%10000; data_Cipher[2] = temp_num/1000;
  56.         temp_num = temp_num%1000; data_Cipher[3] = temp_num/100;
  57.         temp_num = temp_num%100;  data_Cipher[4] = temp_num/10;
  58.         //temp_num = sec%10; //6번째번호는 그냥 %10만 하면되니....
  59.         data_Cipher[5] =  temp_num%10;
  60.  
  61.         if(stl>128) stl=1;
  62.         else stl+=stl;
  63.       }
  64.       delay(1000);
  65.       LED_control(stl);
  66.      
  67.       if(sec==999999) break; //만약에 999999초 이면 타임머 정지.
  68.     }
  69.   }
  70. }
  71.  
  72. int clear(void) //값을 시원하게 클리어
  73. {
  74.   data_Cipher[0] = 0;
  75.   data_Cipher[1] = 0;
  76.   data_Cipher[2] = 0;
  77.   data_Cipher[3] = 0;
  78.   data_Cipher[4] = 0;
  79.   data_Cipher[5] = 0;
  80. }
  81.  
  82. void LED_control(uint8_t da)
  83. {
  84.   for(int i=0; i<8; i++)
  85.   {
  86.     digitalWrite(LED[i], (da >> i) & 0x1);
  87.   }
  88. }
  89.  
  90. void FND_select(uint8_t da)
  91. {
  92.   for(int i=0; i<6; i++)
  93.     digitalWrite(pin_FND_SELECT[i], (da>>i) & 0x01);
  94. }
  95.  
  96. void FND_data_out(uint8_t da)
  97. {
  98.   for(int i=0; i<8; i++)
  99.     digitalWrite(pin_FND_DATA[i], (da>>i) & 0x01);
  100. }
  101.  
  102. void FND_ISR(void)
  103. {
  104.   static int i=0;
  105.   FND_data_out(0);
  106.   FND_select(~(0x001<<i));
  107.   FND_data_out(FND_data[data_Cipher[i]]);
  108.   if(i==5){i=0;}
  109.   else{i++;}
  110. }
RAW Paste Data