Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. int local_ammount;
  2. int local_state=0;
  3. int local_prev=-1;
  4. int local_sensity = 30; // kalibracja
  5. int local_current = 0;
  6.  
  7. int _min = -1;
  8. int _max = -1;
  9. int _prev = -1;
  10.  
  11. int threshold = 0;
  12. int threshold_ammount = 0;
  13. int threshold_black = 160;
  14. int threshold_white = 170;
  15. //int threshold_black = 90;
  16. //int threshold_white = 100;
  17.  
  18. int srednia(int val){
  19. if (_prev==-1){_prev=val;}
  20. else{
  21. _prev = val;
  22. val = (val +_prev ) / 2;
  23. }
  24. return val;
  25. }
  26.  
  27. void setCurrentLocal(int val){
  28. if (local_prev == -1){ local_prev=val;}
  29. else{
  30. local_state += ( val - local_prev );
  31.  
  32. if (local_state > local_sensity) {local_state = local_sensity;}
  33. if (local_state < -1*local_sensity) {local_state = -local_sensity;}
  34. if (local_state > 0 ) {local_current =2;}
  35.  
  36. if (local_state <= -1* local_sensity and local_current==2){
  37. local_current = 1;
  38. } // pretendent do czarnego
  39. if (local_prev < val){
  40. if (local_current==1){ local_ammount +=1; local_current=0;}
  41. }
  42. local_prev = val;
  43. }
  44. }
  45.  
  46.  
  47. void setCurrentThreshold(int val){
  48. if (val <= threshold_black){
  49. if(threshold==1){ threshold_ammount+=1; }
  50. threshold = -1;
  51. };
  52. if (val >= threshold_white){
  53. threshold = 1;
  54. };
  55. };
  56.  
  57.  
  58. int main() {
  59. int val = srednia(10);
  60. setCurrentThreshold(val);
  61. setCurrentLocal(val);
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement