Skip to content

Instantly share code, notes, and snippets.

@dyadica
Last active July 15, 2016 10:07
Show Gist options
  • Save dyadica/0c9a37433141b83e6786044889865a6b to your computer and use it in GitHub Desktop.
Save dyadica/0c9a37433141b83e6786044889865a6b to your computer and use it in GitHub Desktop.
int sensorPin = A0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int sensorReading = analogRead(sensorPin);
// Output the raw sensor reading
Serial.println(sensorReading);
// Using map(); convert to a range like 0-100. Use the
// raw values to determine the from values (0,975)
int sensor0to255 = map(sensorReading, 0, 975, 0, 255);
Serial.println(sensor0to255);
// Slow down the output for easier reading
delay(250);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment