> Club Elektronika: Clubek 1: Penjelasan Program Arduino

Clubek 1: Penjelasan Program Arduino


22 CHF
Proyek tentang bagaimana mengambil data dari database MySQL dan menampilkannya di 7 segment LED Display. 
Videonya bisa di lihat di clubek1

Dilanjutkan dengan video bagian yang:
ke 2 tentang penjelasan rangkaian  dan


int number=48, l=0, r=0, d=500, z=48; // d untuk delay
int jmlh=4; // jumlah Digit = jmlh pesanan*2

int storeIn[]= {48, 48, 48, 48}; // Initial Array

#include <stdlib.h> // for the atol() function

int BCD_A = 7; //pin for BCD
int BCD_B = 8; //pin for BCD
int BCD_C = 12; //pin for BCD
int BCD_D = 13; //pin for BCD

int Display;

void setup(){  
  pinMode(2, OUTPUT);//Latch
  pinMode(3, OUTPUT);//Clock
  pinMode(4, OUTPUT);//Data
  pinMode(BCD_A, OUTPUT);//Data for BCD
  pinMode(BCD_B, OUTPUT);//Data for BCD
  pinMode(BCD_C, OUTPUT);//Data for BCD
  pinMode(BCD_D, OUTPUT);//Data for BCD
  
 digitalWrite(2, LOW);
 Serial.begin(115200);
  
} //end void setup

  
void loop()
  {   
   if (Serial.available() < jmlh) // the data isn`t yet coming
     {      
        for (l=0; l<jmlh; l++)
                    {
                      number=storeIn[l];
                      sevenseg(number);  // melakukan program sevenseg                      
                     } // end for (l=0; l<jmlh, l++) 
       }  // end if (Serial.available() > 1) 
       
        else 
            {  
              for (r=0; r<jmlh; r++)
                    {
                      storeIn[r]=Serial.read(); 
                     } // end for (r=0; r<jmlh; r++)                     
                      number=storeIn[r-1]; 
             }  // end else 
    } // end  loop
    
    
void sevenseg(int number)
  {    
    #define BCD_ON  HIGH
    #define BCD_OFF  LOW
    
    ////////////////////////////////////////////////////////
    // Mengirim data angka ke BCD dan menyalakan display- //
    // yang tepat                                         //
    ////////////////////////////////////////////////////////

       switch (number)
          {          
          case '0': // 0000
            digitalWrite(BCD_A, BCD_OFF);
            digitalWrite(BCD_B, BCD_OFF);
            digitalWrite(BCD_C, BCD_OFF);
            digitalWrite(BCD_D, BCD_OFF);
            
            updateShiftRegister();  // menyalakan Display yg tepat            
            break;
        
          case '1': // 0001
            digitalWrite(BCD_A, BCD_ON);
            digitalWrite(BCD_B, BCD_OFF);
            digitalWrite(BCD_C, BCD_OFF);
            digitalWrite(BCD_D, BCD_OFF);
            
            updateShiftRegister();            
            break;
            
          case '2': // 0010
            digitalWrite(BCD_A, BCD_OFF);
            digitalWrite(BCD_B, BCD_ON);
            digitalWrite(BCD_C, BCD_OFF);
            digitalWrite(BCD_D, BCD_OFF);
            
            updateShiftRegister();            
            break; 
           
          case '3': // 0011
            digitalWrite(BCD_A, BCD_ON);
            digitalWrite(BCD_B, BCD_ON);
            digitalWrite(BCD_C, BCD_OFF);
            digitalWrite(BCD_D, BCD_OFF);
            
            updateShiftRegister();            
            break;
           
          case '4':
            digitalWrite(BCD_A, BCD_OFF);
            digitalWrite(BCD_B, BCD_OFF);
            digitalWrite(BCD_C, BCD_ON);
            digitalWrite(BCD_D, BCD_OFF);
            
            updateShiftRegister();            
            break;  
           
            
          case '5':
            digitalWrite(BCD_A, BCD_ON);
            digitalWrite(BCD_B, BCD_OFF);
            digitalWrite(BCD_C, BCD_ON);
            digitalWrite(BCD_D, BCD_OFF);
            
            updateShiftRegister();            
            break;
        
          case '6':
            digitalWrite(BCD_A, BCD_OFF);
            digitalWrite(BCD_B, BCD_ON);
            digitalWrite(BCD_C, BCD_ON);
            digitalWrite(BCD_D, BCD_OFF);
            
            updateShiftRegister();  
            break;
            
          case '7':
            digitalWrite(BCD_A, BCD_ON);
            digitalWrite(BCD_B, BCD_ON);
            digitalWrite(BCD_C, BCD_ON);
            digitalWrite(BCD_D, BCD_OFF);
            
            updateShiftRegister();            
            break; 
           
          case '8':
            digitalWrite(BCD_A, BCD_OFF);
            digitalWrite(BCD_B, BCD_OFF);
            digitalWrite(BCD_C, BCD_OFF);
            digitalWrite(BCD_D, BCD_ON);
            
            updateShiftRegister();            
            break;
           
          case '9':
            digitalWrite(BCD_A, BCD_ON);
            digitalWrite(BCD_B, BCD_OFF);
            digitalWrite(BCD_C, BCD_OFF);
            digitalWrite(BCD_D, BCD_ON);
            
            updateShiftRegister();            
            break; 
            
          }// end switch(tens)
           
      digitalWrite(2, LOW);
 } // end sevenseg


void updateShiftRegister()
  {
   updateDisplay();  
 
    digitalWrite(2, LOW);
    shiftOut(4, 3, MSBFIRST, Display);
    digitalWrite(2, HIGH);
    delay(d);
    }


void updateDisplay()
  {
         switch (z)
            {
              case '0':
              Display= 1;
              break;
              
              case '1':
              Display= 2;
              break;
              
              case '2':
              Display= 4;
              break;
              
              case '3':
              Display= 8;
              z=47; // Go back again to the begin.
              break;                           
             } // end switch (z)
             
           z++;
  } // end void updateDisplay()
  
 


1 komentar :

  1. maap bosku, bagian yang ngambil data dari databasenya gimana ya? makasih.

    BalasHapus