Skip to content

Instantly share code, notes, and snippets.

@akinozgen
Created April 2, 2018 11:50
Show Gist options
  • Save akinozgen/8841d8a34b6bf1d82c6e7d0b28443b37 to your computer and use it in GitHub Desktop.
Save akinozgen/8841d8a34b6bf1d82c6e7d0b28443b37 to your computer and use it in GitHub Desktop.
//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