Latihan

 



Modul 1
ON OFF LED dengan PUSHBUTTON

1 Board Arduino
   Kabel Jumper
1 Breadboard
1 Resistor 10K
1 Resistor 100 Ohm  
1 Pushbutton

Program

int button=9;
int nilaibutton;
int count;
int led=13;

void setup(){
pinMode(led,OUTPUT);
pinMode(button,INPUT);
  }

void loop(){
nilaibutton=digitalRead(button);
  if(nilaibutton ==0){
    count++;
    delay(300);
    if(count == 1){
      digitalWrite(led,HIGH);
      }
  }if(count == 2){
    digitalWrite(led,LOW);
    count=0;
  }
    }


Modul 2
KONTROL 7 SEGMENT dengan POTENSIOMETER
1 Board Arduino
   Kabel Jumper
1 Breadboard
1 Potensiometer 
2 Resistor 330 Ohm  

Program
#define POT A5 
int a=2,b=3,c=4,d=5,e=6,f=7,g=8;

int no[10][7] = { 
//common Anode
 { 0,0,0,0,0,0,1 }, // 0 
 { 1,0,0,1,1,1,1 }, // 1 
 { 0,0,1,0,0,1,0 }, // 2 
 { 0,0,0,0,1,1,0 }, // 3 
 { 1,0,0,1,1,0,0 }, // 4 
 { 0,1,0,0,1,0,0 }, // 5 
 { 0,1,0,0,0,0,0 }, // 6 
 { 0,0,0,1,1,1,1 }, // 7 
 { 0,0,0,0,0,0,0 }, // 8 
 { 0,0,0,0,1,0,0 }  // 9  
  
  
/* common kathode 
 { 1,1,1,1,1,1,0 }, // 0 
 { 0,1,1,0,0,0,0 }, // 1 
 { 1,1,0,1,1,0,1 }, // 2 
 { 1,1,1,1,0,0,1 }, // 3 
 { 0,1,1,0,0,1,1 }, // 4 
 { 1,0,1,1,0,1,1 }, // 5 
 { 1,0,1,1,1,1,1 }, // 6 
 { 1,1,1,0,0,0,0 }, // 7 
 { 1,1,1,1,1,1,1 }, // 8 
 { 1,1,1,1,0,1,1 }  // 9 
  */
  
 }; 
 
void setup() 
{ 
 // set pin 
 pinMode(a, OUTPUT); 
 pinMode(b, OUTPUT); 
 pinMode(c, OUTPUT); 
 pinMode(d, OUTPUT); 
 pinMode(e, OUTPUT); 
 pinMode(f, OUTPUT); 
 pinMode(g, OUTPUT); 
 
} 
void loop() 
{ 
 int setNom = analogRead(POT); 
 setNom = map(setNom,0,1023,0,10); 
 Serial.println(setNom); 
 if(setNom<10) Nom_Write(setNom); 
} 

void Nom_Write(int nomor) 
{ 
 int pin= 2; 
 for (int j=0; j < 7; j++) { 
 digitalWrite(pin, no[nomor][j]); 
 pin++; 
 } 
}

Comments

Popular Posts