Im getting annyoed nothing works anymore.
This code is supposed to control the direction of the dc motor. When I write "right" it spins right, but when I write "left" it keeps spinning right.
And when I but the "left" if statement on, then the left one spins but right doesnt.
the code:
int motSpeedPin=3;
byte speed=90;
int leftPin=5;
int leftVal;
int rightPin=4;
int rightVal;
String msg="Kerro suunta";
void setup() {
Serial.begin(9600);
pinMode(motSpeedPin,OUTPUT);
pinMode(leftPin,OUTPUT);
pinMode(rightPin,OUTPUT);
}
void loop() {
// step one step:
Serial.print(speed);
Serial.print(" ");
Serial.println(msg);
while(Serial.available()==0) {
}
if(Serial.readString()=="right"){
digitalWrite(leftPin,LOW);
digitalWrite(rightPin,HIGH);
}
if(Serial.readString()=="left") {
digitalWrite(leftPin,HIGH);
digitalWrite(rightPin,LOW);
}
digitalWrite(motSpeedPin,speed);
}
8 Replies
NeverMind I figure it out
Great! One tip, itll be much easier for people to help you with your code if its highlighted by the auto-formatter, put it after a line that starts with this, and ends with the three ticks again
```ino
<your code here>
`
thanks
Hit <enter> after the ```ino (enter here... new line before code) and youll be golden π
suomalainen?
okei
ukei
thanks a lot
Youre welcome!