Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int local_ammount;
- int local_state=0;
- int local_prev=-1;
- int local_sensity = 30; // kalibracja
- int local_current = 0;
- int _min = -1;
- int _max = -1;
- int _prev = -1;
- int threshold = 0;
- int threshold_ammount = 0;
- int threshold_black = 160;
- int threshold_white = 170;
- //int threshold_black = 90;
- //int threshold_white = 100;
- int srednia(int val){
- if (_prev==-1){_prev=val;}
- else{
- _prev = val;
- val = (val +_prev ) / 2;
- }
- return val;
- }
- void setCurrentLocal(int val){
- if (local_prev == -1){ local_prev=val;}
- else{
- local_state += ( val - local_prev );
- if (local_state > local_sensity) {local_state = local_sensity;}
- if (local_state < -1*local_sensity) {local_state = -local_sensity;}
- if (local_state > 0 ) {local_current =2;}
- if (local_state <= -1* local_sensity and local_current==2){
- local_current = 1;
- } // pretendent do czarnego
- if (local_prev < val){
- if (local_current==1){ local_ammount +=1; local_current=0;}
- }
- local_prev = val;
- }
- }
- void setCurrentThreshold(int val){
- if (val <= threshold_black){
- if(threshold==1){ threshold_ammount+=1; }
- threshold = -1;
- };
- if (val >= threshold_white){
- threshold = 1;
- };
- };
- int main() {
- int val = srednia(10);
- setCurrentThreshold(val);
- setCurrentLocal(val);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement