1

Тема: x9c103s

http://forum.rcl-radio.ru/uploads/images/2023/11/8226fb219d5824d1761ca0da2ef55152.png


#define CS   2
#define INC  4
#define UD   3

#define STEP 5

int pop,dat=0,dat_old;
bool w=1;


void setup() {
  analogReadResolution(12);
  analogReference(INTERNAL4V096);
  Serial.begin(9600);
  pinMode(CS,OUTPUT);
  pinMode(INC,OUTPUT);
  pinMode(UD,OUTPUT);
  pinMode(A0,INPUT);
  pinMode(11,INPUT_PULLUP);
  pinMode(12,INPUT_PULLUP);
  digitalWrite(CS,LOW);
  cl();
}

void loop() {
   if(digitalRead(11)==LOW){dat+=STEP;w=1;if(dat>100){dat=100;}delay(200);digitalWrite(CS,LOW);}
   if(digitalRead(12)==LOW){dat-=STEP;w=1;if(dat<0){dat=0;}delay(200);digitalWrite(CS,LOW);}
   
   if(dat_old!=dat){pop = dat-pop;
   if(pop>0){up(abs(pop));}
   if(pop<0){dw(abs(pop));}
   pop=dat;
   digitalWrite(CS,HIGH); 
   }
   dat_old=dat;
  if(w==1){w=0;
   delay(50);
   Serial.print(analogRead(A0)/1000.0,3);Serial.println(" V"); 
   Serial.print(pop);Serial.println(" %");
 }
}

void cl(){digitalWrite(UD,LOW);for(int i=0;i<100;i++){digitalWrite(INC,LOW);digitalWrite(INC,HIGH);}}
void up(byte data){digitalWrite(UD,HIGH);for(int i=0;i<data;i++){digitalWrite(INC,LOW);digitalWrite(INC,HIGH);}} 
void dw(byte data){digitalWrite(UD,LOW);for(int i=0;i<data;i++){digitalWrite(INC,LOW);digitalWrite(INC,HIGH);}}