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);
}
asked Aug 18, 2018 at 11:46
2 Answers 2
You need to use Serial.print instead of Serial.write.
answered Aug 18, 2018 at 11:49
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