Created
April 2, 2018 11:50
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//sürücü | |
const int motorA1 = 5; | |
const int motorA2 = 6; | |
const int motorB1 = 10; | |
const int motorB2 = 9; | |
int i=0; | |
int j=0; | |
int state; | |
int vSpeed=255; | |
void setup() { | |
// Pin | |
pinMode(motorA1, OUTPUT); | |
pinMode(motorA2, OUTPUT); | |
pinMode(motorB1, OUTPUT); | |
pinMode(motorB2, OUTPUT); | |
// hız | |
Serial.begin(9600); | |
} | |
void loop() { | |
if(digitalRead(state)==LOW) { state='S'; } | |
if(Serial.available() > 0){ | |
state = Serial.read(); | |
} | |
if (state == '0'){ | |
vSpeed=0;} | |
else if (state == '1'){ | |
vSpeed=100;} | |
else if (state == '2'){ | |
vSpeed=180;} | |
else if (state == '3'){ | |
vSpeed=200;} | |
else if (state == '4'){ | |
vSpeed=255;} | |
/*ileri*/ | |
if (state == 'F') { | |
analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0); | |
analogWrite(motorB1, vSpeed); analogWrite(motorB2, 0); | |
} | |
/*geri*/ | |
//Gelen veri 'B' ise araba geri gider. | |
else if (state == 'B') { | |
analogWrite(motorA1, 0); analogWrite(motorA2, vSpeed); | |
analogWrite(motorB1, 0); analogWrite(motorB2, vSpeed); | |
} | |
/*dur*/ | |
//Gelen veri 'S' ise arabayı durdur. | |
else if (state == 'S'){ | |
analogWrite(motorA1, 0); analogWrite(motorA2, 0); | |
analogWrite(motorB1, 0); analogWrite(motorB2, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment