Advertisement
kokopelli2

Ruben's MIndex code

Jun 29th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float dist[4];
  2.  
  3. int findMaxIndex(float dist[], int size)
  4. {
  5.     //size > 0
  6.     if (size == 1)
  7.         return 0;
  8.  
  9.     int mindex = 0; float max = dist[0];
  10.  
  11.     for(int i = 1; i < size; ++i)
  12.     {  
  13.         if (dist[i] > max)
  14.         {
  15.             max = dist[i];
  16.             mindex = i;
  17.         }
  18.  
  19.     }
  20.  
  21.  
  22.     return mindex;
  23. }
  24.  
  25. void setup()
  26. {
  27.  
  28.  
  29. }
  30.  
  31. void loop()
  32. {
  33.     // Populate dist
  34.  
  35.     int mindex = findMaxIndex(dist, 4);
  36.     // Turn the servo[index] / use free space here
  37.     // float maxelem = dist[mindex];
  38.    
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement