Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float dist[4];
- int findMaxIndex(float dist[], int size)
- {
- //size > 0
- if (size == 1)
- return 0;
- int mindex = 0; float max = dist[0];
- for(int i = 1; i < size; ++i)
- {
- if (dist[i] > max)
- {
- max = dist[i];
- mindex = i;
- }
- }
- return mindex;
- }
- void setup()
- {
- }
- void loop()
- {
- // Populate dist
- int mindex = findMaxIndex(dist, 4);
- // Turn the servo[index] / use free space here
- // float maxelem = dist[mindex];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement