Skip to content

Instantly share code, notes, and snippets.

@giljr
Last active January 23, 2020 11:48
Show Gist options
  • Save giljr/6e65bf4c79d5fa5a4612cdf4430fac50 to your computer and use it in GitHub Desktop.
Save giljr/6e65bf4c79d5fa5a4612cdf4430fac50 to your computer and use it in GitHub Desktop.
/*
AnalogReadPot
Reads an analog input on pin 0, prints the result to the Serial Monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/AnalogReadSerial
*/
// potentiometer connection pin
int potPin = 1;
// val is returned integer numbers
int val = 0;
// the setup routine runs once when you press reset:
void setup() {
pinMode(potPin, INPUT);
// initialize serial communication at 115200 bits per second:
Serial.begin(115200);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 1:
val = analogRead(potPin);
// return out the value you read in byte size: 1023/4
Serial.write(val/4);
// delay in between reads for stability
//delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment