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);
}
Juraj
18.3k4 gold badges31 silver badges49 bronze badges
asked Aug 18, 2018 at 11:46

2 Answers 2

4

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

answered Aug 18, 2018 at 11:49
3

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

Serial.println(potentioVal);

answered Aug 18, 2018 at 11:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.