Page 42 - MODUL TEKNIK PEMROGRAMAN MIKROPROSESOR DAN MIKROKONTROLLER
P. 42

Job 1:                                      Job 2:
                     int Button1 = 2;                            int Button1 = 2;

                     int Button2 = 3;                            int Button2 = 3;
                     int LED = 13;                               int LED = 13;

                     int ButtonState = 0;                        int ButtonState = 0;



                     void setup() {                              void setup() {
                     pinMode(Button1, INPUT);                    pinMode(Button1,INPUT);

                     pinMode(Button2, INPUT);                    pinMode(Button2,INPUT);

                     pinMode(LED, OUTPUT);                       pinMode(LED,OUTPUT);
                     }                                           }
                                                                 void flip() {
                     void loop() {                                 ulang:

                       if(digitalRead(Button1)== LOW){             digitalWrite(LED,LOW);

                         digitalWrite(LED, LOW);                   delay (250);
                       }

                       else if(digitalRead(Button2)== LOW){        if (digitalRead(Button1) == LOW) {
                         digitalWrite(LED, HIGH);                 digitalWrite(LED,LOW);

                       }                                          loop();
                                                                  }
                     }                                             delay (250);

                                                                   if (digitalRead(Button1) == LOW) {

                                                                  digitalWrite(LED,LOW);
                                                                  loop();
                                                                  }
                                                                   digitalWrite(LED,HIGH);
                                                                   delay (200);

                                                                   if (digitalRead(Button1) == LOW) {
                                                                  digitalWrite(LED,LOW);

                                                                  loop();
                                                                  }
                                                                   goto ulang;
                                                                 }

                                                                 void loop() {
                                                                   ul:
                                                                  if (digitalRead(Button2) == LOW){
                                                                  flip();

                                                                 }
                                                                  goto ul;

                                                                 }



                                             Gambar 2. 1 Koding Praktikum













                                                                                                       33
   37   38   39   40   41   42   43   44   45   46   47