A
Arduinoβ€’2mo ago
TheStudier

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
TheStudier
TheStudierOPβ€’2mo ago
NeverMind I figure it out
Tuuli 🎹🎸🀘
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>
TheStudier
TheStudierOPβ€’2mo ago
ino nakki haisee
ino nakki haisee
` thanks
Tuuli 🎹🎸🀘
Hit <enter> after the ```ino (enter here... new line before code) and youll be golden πŸ˜„
TheStudier
TheStudierOPβ€’2mo ago
suomalainen? okei
Tuuli 🎹🎸🀘
ino #include code on the same line as ino
int? why isnt it coloured?
ino #include code on the same line as ino
int? why isnt it coloured?
#include code on the next line - look, im formatted in a cool colour :)
int oh wow this is coloured too!
<enter line before the closing `s>
#include code on the next line - look, im formatted in a cool colour :)
int oh wow this is coloured too!
<enter line before the closing `s>
TheStudier
TheStudierOPβ€’2mo ago
ukei thanks a lot
Tuuli 🎹🎸🀘
Youre welcome!

Did you find this page helpful?