// 3, 5, 6, 9, 10, 11 490 Hz (pins 5 and 6: 980 Hz)
const int input = A0;
const int cikispin = 5;
const double A=10;
const double B=0.00025;
double setnoktasi = 101;
double hata = 0;
double eskihata = 0;
double integral = 0;
double eskiintegral = 0;
byte zaman=10; //mS bekleme ** örnekleme zamanı
int adc = 0;
int cikis = 0;
int eskicikis = 0;
void setup()
{
//Serial.begin(9600);
eskihata = setnoktasi;
integral = setnoktasi;
eskiintegral = setnoktasi;
}
void loop()
{
adc = analogRead(input);
adc = ((adc) >> 2);
//Serial.println(adc);
hata = setnoktasi - adc;
integral = B*(hata)+(eskiintegral);
cikis = (integral) + A*(hata);
if(cikis>250)
{
cikis=eskicikis;
cikis=250; //255 yazılabilir
}
if(cikis<1)
{
cikis=eskicikis;
cikis=0; //0 min
}
delay(zaman);
analogWrite(cikispin, cikis);
eskihata = hata;
eskiintegral = integral;
}