For this project, you will be reading analog data from an infrared distance sensor (made by Sharp) and modeling the relationship between the analog values and the distances.
Everyone has been issued one Sharp distance sensor, with a 3-pin cable.
At the end of this project, you should be able to:
Wiring:
#include "PeriodicAction.h"
const int sharpPin = A1;
This example corresponds to Arduino analog pin A1.
void sensor_display_step(){...};that samples from your distance sensor and prints out its value.
To read from the analog port that we defined above, use the following:
int val = analogRead(sharpPin);
This will give you a value in the range 0 ... 1023, corresponding to voltages 0 to 3.3V
To print out the values, use the standard Serial.printf() function:
Serial.printf("Hello, World!\n");
See the printf() documentation for more information about formatted printing: printf().
void loop() { // Call the sensor_display_step() function every 1000 ms static PeriodicAction sensor_display_task(1000, sensor_display_step); // Check to see if the task is ready to be executed sensor_display_task.step(); }
Last modified: Wed Mar 3 22:34:32 2021