//#include <Arduino.h>
int8_t angka=0;
#define DATA(x) digitalWrite(2,x);
#define CLOCK(x) digitalWrite(4,x);
#define LATCH(x) digitalWrite(3,x);
#define BUZZ(x) digitalWrite(6,x);
#define FAN 5
#define LED1(x) digitalWrite(A0,!x);
#define LED2(x) digitalWrite(A1,!x);
#define LED3(x) digitalWrite(A2,!x);
#define LED4(x) digitalWrite(A3,!x);
#define LED5(x) digitalWrite(A4,!x);
#define LED6(x) digitalWrite(A5,!x);
#define LED7(x) digitalWrite(12,!x);
#define LED8(x) digitalWrite(11,!x);
#define LED9(x) digitalWrite(10,!x);
#define s1 digitalRead(7)
#define s2 digitalRead(8)
#define s3 digitalRead(9)
int jumlahTekanan;
int PWM=0;
//data array led
uint16_t dtled[11]={
    0b000000000, // led padam
		0b000000001,  //led1
		0b000000010,  //led2
		0b000000100,  //led3
		0b000001000,  //led4
		0b000010000,  //led5
		0b000100000,  //led6
		0b001000000,  //led7
		0b010000000,  //led8
		0b100000000  //led9
};

// data array 7segment
uint8_t dt7s[10]={
		0b00000011,
		0b10011111,
		0b00100101,
		0b00001101,
		0b10011001,
		0b01001001,
		0b01000001,
		0b00011111,
		0b00000001,
		0b00001001
};


int8_t counter;

void setup() {
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode (7, INPUT_PULLUP);
  pinMode (8, INPUT_PULLUP);
  pinMode (9, INPUT_PULLUP);

  pinMode(A0,OUTPUT);digitalWrite(A0,1);
  pinMode(A1,OUTPUT);digitalWrite(A1,1);
  pinMode(A2,OUTPUT);digitalWrite(A2,1);
  pinMode(A3,OUTPUT);digitalWrite(A3,1);
  pinMode(A4,OUTPUT);digitalWrite(A4,1);
  pinMode(A5,OUTPUT);digitalWrite(A5,1);
  pinMode(12,OUTPUT);digitalWrite(12,1);
  pinMode(11,OUTPUT);digitalWrite(11,1);
  pinMode(10,OUTPUT);digitalWrite(10,1);


 // Serial.begin(9600);
}


void mxled(uint8_t dt){
	if(dtled[dt]>>0&1){LED1(1);}else {LED1(0);}  
	if(dtled[dt]>>1&1){LED2(1);}else {LED2(0);}  
	if(dtled[dt]>>2&1){LED3(1);}else {LED3(0);}  
	if(dtled[dt]>>3&1){LED4(1);}else {LED4(0);}  
	if(dtled[dt]>>4&1){LED5(1);}else {LED5(0);}  
	if(dtled[dt]>>5&1){LED6(1);}else {LED6(0);}  
	if(dtled[dt]>>6&1){LED7(1);}else {LED7(0);}  
	if(dtled[dt]>>7&1){LED8(1);}else {LED8(0);} 
	if(dtled[dt]>>8&1){LED9(1);}else {LED9(0);}  
}



void disp(uint8_t dt){
	uint8_t pul=dt/10;  //-->2
	uint8_t sat=dt%10;  //-->5

	for(int i=0; i<8; i++){
		if(dt7s[pul]>>i&1){DATA(1);} else {DATA(0);}
		CLOCK(0);
		CLOCK(1);
	}	
  for(int i=0; i<8; i++){
		if(dt7s[sat]>>i&1){DATA(1);} else {DATA(0);}
		CLOCK(0);
		CLOCK(1);
	}


	LATCH(0);
	LATCH(1);
}

void loop() 
{
disp(counter);
// disp(counter);counter++;
// delay(100);
// if (counter>=99){counter=0;}

// uint8_t urut[8]={1,2,3,6,9,8,7,4};
// for(int i=0; i<8; i++){
// 	mxled(urut[i]);
// 		delay(50);}

if(s1==0){
	disp(counter);counter++;
	if (counter>=99){counter=0;}
	 delay(100);
   }
if(s2==0){
	disp(counter);counter;
	if (counter=0){counter=99;}
	 delay(100);
	 }
if(s3==0){
	disp(counter);counter--;
	if (counter<=0){counter=99;}
	 delay(100);
	 }
	 }
	 

	 



74HC595
74HC595