0

My potentiometer reads out t's or u's in my serial. I believe that my potentiometer is wired correctly. What am I missing? Here is my code:

#include <VarSpeedServo.h>

VarSpeedServo servo;
const byte buttonLeft = 2;
const byte buttonRight = 3;
const int led = 7;
const int potentioPin = A0;
int potentioVal = 0;

void setup() {
  Serial.begin(9600);
  servo.attach(11);

  // PIN MODES
  pinMode(buttonLeft, INPUT);
  pinMode(buttonRight, INPUT);
  pinMode(led, OUTPUT);

  // INTERRUPT
  attachInterrupt(digitalPinToInterrupt(buttonLeft), turnServo, FALLING);
}

void loop() {
  int stateBtnLeft = digitalRead(buttonLeft);
  int stateBtnRight = digitalRead(buttonRight);

  if(stateBtnLeft == 0 && stateBtnRight == 0){
    digitalWrite(led, HIGH);
  } else {
    digitalWrite(led, LOW);
  }
}

void turnServo(){
  Serial.println("Button was pushed");
  potentioVal = analogRead(0);
  Serial.write("Servo moving with speed ");
  Serial.write(potentioVal);
  Serial.println("");
  //servo.write(180, potentioVal, true);
  //Serial.write("Reached position of motor");
  //lightLed();
}

void lightLed(){
  digitalWrite(led, HIGH);
  delay(2000);
  digitalWrite(led, LOW);
}
4

You need to use Serial.print instead of Serial.write.

3

write() is a function for binary data. I you want to print the number as text, use print() or println().

Serial.println(potentioVal);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.