int ds =12;
int latch = 11;
int clk = 9;
int satuan, puluhan,ratusan;
int i;
String state ="";
byte angka[10]{
  B00000011, //angka 0
  B10011111, //angka 1
  B00100101, //angka 2
  B00001101, //angka 3
  B10011001, //angka 4
  B01001001, //angka 5
  B01000001, //angka 6
  B00011111, //angka 7
  B00000001, //angka 7
  B00001001 //angka 9
};
int sensor;
void setup() {
 pinMode(ds, OUTPUT);
 pinMode(latch, OUTPUT);
 pinMode(clk, OUTPUT);
 pinMode(2, INPUT_PULLUP);
 Serial.begin(9600);

}

void loop() {
  sensor = digitalRead(2);
  
  if(state == ""&& sensor == 0){
    state = "tambah";
  }

  if(state == "tambah" && sensor == 1){
    i+=2;
    state = "";
  }
  if(i >= 99){
    i = 99;
  }
   satuan = i%10;
   puluhan = i/10;
   ratusan = i/100;

  Serial.println(String()+"Sensor ="+sensor+" "+"i = "+i);
  // Serial.println(puluhan);
    // digitalWrite(latch, LOW);
    // shiftOut(ds,clk,LSBFIRST,angka[9]);
    // digitalWrite(latch, HIGH);
  // for(int i = 0; i<1000; i++){
  //   satuan = i%10;
  //   puluhan = i/10;
  //   ratusan = i/100;
  //   if(puluhan >9){
  //     puluhan = puluhan % 10;
  //   }
     
    
    digitalWrite(latch, LOW);  
    shiftOut(ds,clk,LSBFIRST,angka[satuan]); //satuan
    shiftOut(ds,clk,LSBFIRST,angka[puluhan]); //puluhan
    shiftOut(ds,clk,LSBFIRST,angka[ratusan]); //puluhan\
    digitalWrite(latch, HIGH);
    // delay(500);
  }
// }
74HC595
74HC595
74HC595