int deg_hori = 90; // default horizon int deg_vert = 45; // default vertical int duty;
// LDR sensor pin int ldr_lt = 32; // Left_Top LDR pin int ldr_rt = 33; // Right_Top LDR pin int ldr_ld = 34; // Left_Down LDR pin int ldr_rd = 35; // Right_Down LDR pin
// LDR sensor value int lt[10]; int rt[10]; int ld[10]; int rd[10];
// Sensitivity (tolerance) int tolh = 150; // horizon tolerance int tolv = 150; // vertical tolerance
// initial sensor correction value int avlt_cali = 0; // 초기값 보정 int avrt_cali = 350; // (센서에 밝은 빛을 직접 가하여 최대값을 측정한 뒤 편차를 사용) int avld_cali = 330; int avrd_cali = 430;
int avlt = 0; int avrt = 0; int avld = 0; int avrd = 0;
for (int i=0; i<10; i++) { lt[i] = analogRead(ldr_lt); // Left Top avlt = avlt + lt[i] - avlt_cali; rt[i] = analogRead(ldr_rt); // Right Top avrt = avrt + rt[i] - avrt_cali; ld[i] = analogRead(ldr_ld); // Left Down avld = avld + ld[i] - avld_cali; rd[i] = analogRead(ldr_rd); // Right Down avrd = avrd + rd[i] - avrd_cali; }
avlt = avlt / 10; avrt = avrt / 10; avld = avld / 10; avrd = avrd / 10; int avt = (avlt + avrt) / 2; // Average of Top value int avd = (avld + avrd) / 2; // Average of Down value int avl = (avlt + avld) / 2; // Average of Left value int avr = (avrt + avrd) / 2; // Average of Right value.
int dvert = avt - avd; // Difference Top, Down int dhoriz = avl - avr; // Difference Left, Right