Skip to content

Instantly share code, notes, and snippets.

@margmarg
Created September 16, 2021 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save margmarg/56b5c9201c806d51f592b24f3cc6fe3b to your computer and use it in GitHub Desktop.
Save margmarg/56b5c9201c806d51f592b24f3cc6fe3b to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo myservo;
int SERVO_PIN = 9;
int BUTTON_PIN = 3;
boolean button = LOW;
void setup() {
pinMode(BUTTON_PIN, INPUT);
Serial.begin(9600);
myservo.attach(SERVO_PIN);
}
void loop() {
int pot = analogRead(A0);
Serial.print(pot);
// pot = map(pot, 0, 1023, 0, 180);
pot = map(pot, 0, 1023, 40, 120);
Serial.print(" maps to ");
Serial.print(pot);
myservo.write(pot);
// button = digitalRead(BUTTON_PIN);
//
// if (button == HIGH) {
// myservo.write(120);
//
// } else {
// myservo.write(90);
//
// }
delay(10);
Serial.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment