Microchip® Advanced Software Framework

common/applications/sensors/prox_calibrate/main.c File Reference

Common Sensor Service Proximity Sensor Calibration Example.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include <stdio.h>
#include <asf.h>
#include <led.h>


#define ALL_LEDS   (LED1 | LED2 | LED3 | LED4)
#define NUM_BLINK_LEDS   (4)
#define PROMPT_LED   LED4 /* Blink while waiting for user input */
#define PROX_CURRENT_mA   (150) /* Current for proximity sensor LEDs (mA) */
#define SET_PROX_CURRENT   (true) /* If true, manually set proximity current */
#define SWITCH_PRESSED   gpio_pin_is_low(GPIO_PUSH_BUTTON_0)


int main (void)
 Proximity sensor threshold calibration application. More...
static void prompt_user (char *prompt_string)
 User prompt routine. More...


static const uint32_t led_array [NUM_BLINK_LEDS] = {LED1, LED2, LED3, LED4}
static const char *const prox_labels [4]
 Strings to display based on proximity values. More...

#define ALL_LEDS   (LED1 | LED2 | LED3 | LED4)

Referenced by main(), and prompt_user().

#define NUM_BLINK_LEDS   (4)

Referenced by main().

#define PROMPT_LED   LED4 /* Blink while waiting for user input */

Referenced by prompt_user().

#define PROX_CURRENT_mA   (150) /* Current for proximity sensor LEDs (mA) */

Referenced by main().

#define SET_PROX_CURRENT   (true) /* If true, manually set proximity current */
#define SWITCH_PRESSED   gpio_pin_is_low(GPIO_PUSH_BUTTON_0)

Referenced by prompt_user().

int main ( void  )

Proximity sensor threshold calibration application.

This application illustrates the use of the sensor_calibrate() function to set the proximity detection thresholds in a 3-channel proximity sensor. This threshold is the level at which the sensor will report that an object is near the device.

The calibration sequence requires three steps, one for each channel. During each step, an object is placed at the desired distance in front of the sensor, and the user presses the button on the board to trigger a proximity reading.

After Step 3 is completed, the threshold values for the sensor are calculated and are written to non-volatile (flash) memory on the microcontroller. These values will continue to be used for future proximity readings, unless they are overwritten by an application calling the sensor_set_threshold function for the proximity sensor channel(s).

References ALL_LEDS, delay_ms, led_array, MANUAL_CALIBRATE, NULL, NUM_BLINK_LEDS, prompt_user(), PROX_CURRENT_mA, prox_data, prox_dev, prox_labels, sensor_data_t::proximity, sensor_data_t::scaled, sensor_attach(), sensor_calibrate(), SENSOR_CHANNEL_ALL, SENSOR_ERR_IO, sensor_get_proximity(), sensor_get_threshold(), sensor_platform_init(), sensor_set_channel(), sensor_set_current(), SENSOR_THRESHOLD_NEAR_PROXIMITY, and SENSOR_TYPE_PROXIMITY.

static void prompt_user ( char *  prompt_string)

User prompt routine.

This routine prompts the user to press the button and then waits for him to do so.

References ALL_LEDS, delay_ms, PROMPT_LED, and SWITCH_PRESSED.

Referenced by main().

const uint32_t led_array[NUM_BLINK_LEDS] = {LED1, LED2, LED3, LED4}

Referenced by main().

const char* const prox_labels[4]
Initial value:
= {
"none ",
"FAR ",

Strings to display based on proximity values.

Referenced by main().