#include<Wire.h> //Include kutuphane ı2 data Wire
#define MCP4725 0X60
unsigned long adc;
unsigned long buffer[3];
unsigned int rdtx=0;
unsigned int rdtmax=20;
unsigned long karsilastir=0;
unsigned int karsmax=260;
byte trp=2; // tr out:
byte trn=3; // tr cıkış :
byte kazancled=4; // led output:
byte npoutled=5; // led cıkısı:
byte pwrled=6; // led cıkış :
byte incompy = 7; // buton opamp 1-0 gırış:
byte outcompv=8; // ao-a1 karsılastırma cıkış :
byte incompx = 9; // 8 out koprusu 1-0 gırış:
byte setswic=10; // led cıkısı:
void setup()
{
pinMode ( trp, OUTPUT ); // s :
pinMode ( trn , OUTPUT ); // s :
pinMode ( kazancled, OUTPUT ); // s :
pinMode (npoutled,OUTPUT); // sinyal cıkış NPN ve PNP out :
pinMode (pwrled,OUTPUT); // power ve rdt flaşör :
pinMode(incompy, INPUT); // modlar :
pinMode ( outcompv , OUTPUT ); // s :
pinMode(incompx, INPUT); // modlar :
pinMode ( setswic, OUTPUT ); // s :
Wire.begin(0x60);
Wire.setClock (400000);
}
void loop()
{
karsilastir = analogRead(A6); if (karsilastir <= karsmax )
{digitalWrite(setswic, 1); delay (20);}
else
{digitalWrite(setswic, 0); delay (22); }
{
adc = analogRead(A7);
adc = map(adc, 0 ,1023 ,0,4095 ) ;
buffer[0] = 0b01000000;
buffer[1] = adc >> 4;
buffer[2] = adc << 4;
Wire.beginTransmission (0x60);
Wire.write(buffer[0]);
Wire.write(buffer[1]);
Wire.write(buffer[2]);
Wire.endTransmission();
{delay (20);}
{
rdtx = analogRead(A2);
if (rdtx <= rdtmax )
{digitalWrite(pwrled, 1); delay (20);}
else
{digitalWrite(pwrled, 0); delay (50);}
{digitalWrite(pwrled, 1); delay (60);}
{
unsigned long compr1 ,compr2 ;
compr1 = analogRead ( A0) ;
compr2 = analogRead ( A1) ;
if (compr1 <= compr2 )
{digitalWrite (outcompv ,1); delay(10);}
else
{digitalWrite (outcompv ,0); delay (10);}
}
{
bool incompx = digitalRead(7);
bool incompy = digitalRead(9);
if (incompx == 1 && incompy == 1)
{digitalWrite(trp, 1);
digitalWrite(trn, 1);
digitalWrite(npoutled, 1); delay (150); }
else
{digitalWrite(trp, 0);
digitalWrite(trn, 0);
digitalWrite(npoutled, 0); delay (40); }
}
}
}
}