<commit_before>/* arduino_distance
 * Uses VL53L0X Time-of-Flight Lidar sensor for distance measurement
 * Stepper motor rotation
 * Work in progress - <NAME>
 */

#include <Wire.h>
#include <VL53L0X.h>

VL53L0X sensor;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  sensor.init();
  sensor.setTimeout(500);
  sensor.setMeasurementTimingBudget(100000); // For higher accuracy measurement (up to 100ms)(value in microseconds)
}

void loop()
{
  int a;
  int lidar_array[3];
  populate_lidar_array(lidar_array);
  a = average_lidar_array(lidar_array);
  Serial.print(a);
  Serial.println();
}

int populate_lidar_array(int lidar_array[])
{
  int i;
  int len = sizeof(lidar_array);
  for (i = 0; i = (len-1); i = i +1)
  {
    lidar_array[i] = sensor.readRangeSingleMillimeters();
  }
}

int average_lidar_array(int lidar_array[])
{
  int i;
  int len = sizeof(lidar_array);
  int sum = 0;
  for (i = 0; i = (len-1); i = i + 1)
  {
    sum += lidar_array[i];  
  }
  int result;
  result = ((float) sum) / len;
  return result;
}
  
  
<commit_msg>Array averaging finally works. Variable trial accuracy now!<commit_after>/* arduino_distance
 * Uses VL53L0X Time-of-Flight Lidar sensor for distance measurement
 * Stepper motor rotation
 * Work in progress - <NAME>
 */

#include <Wire.h>
#include <VL53L0X.h>
#define average_trials 3

VL53L0X sensor;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  sensor.init();
  sensor.setTimeout(500);
  sensor.setMeasurementTimingBudget(100000); // For higher accuracy measurement (up to 100ms)(value in microseconds)
}

void loop()
{
  int avg;
  int lidar_array[average_trials];
  populate_lidar_array(lidar_array);
  avg = average_lidar_array(lidar_array);
  Serial.print(avg);
  Serial.println();
}

int populate_lidar_array(int lidar_array[])
{
  for (int i = 0; i < average_trials; i = i +1)
  {
    lidar_array[i] = get_distance();
  }
}

int average_lidar_array(int lidar_array[])
{
  int sum = 0;
  for (int i = 0; i < average_trials; i = i + 1)
  {
    sum += lidar_array[i];  
  }
  int result;
  result = ((float) sum) / average_trials;
  return result;
}
  
int get_distance()
{
  return sensor.readRangeSingleMillimeters();
}

{'fraction_non_alphanumeric': 0.13217866909753875, 'fraction_numerical': 0.02917046490428441, 'mean_word_length': 3.888641425389755, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3936688', 'n_tokens_mistral': 901, 'n_tokens_neox': 847, 'n_words': 200}