Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- */
- int potPin = 2;
- int ms = 7;
- bool isHigh = false;
- double pwmval = 0.0;
- Servo victor;
- int victorpin = 10;
- bool runonce = true;
- void setup() {
- Serial.begin(9800);
- victor.attach(victorpin);
- pinMode(ms, INPUT);
- }
- void loop() {
- pwmval = analogRead(potPin);
- isHigh = (digitalRead(ms) == HIGH);
- if (isHigh) {
- pwmval *= -1;
- }
- pwmval = map(pwmval, -1023, 1023, 0, 180);
- victor.write(pwmval);
- }
- void pwmcalibration() {
- if (runonce) {
- victor.write(180);
- delay(2000);
- victor.write(0);
- delay(2000);
- victor.write(90);
- delay(2000);
- runonce = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement