Created
September 16, 2021 02:20
-
-
Save margmarg/56b5c9201c806d51f592b24f3cc6fe3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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