Created
June 1, 2018 22:28
-
-
Save eroberer/742fe3f7dfe77fba2b55b1cdb85daab1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#define ag_ismi "Robot" | |
#define ag_sifresi "robot58." | |
int motor1 = 6; | |
int motor2 = 8; | |
int motor3 = 11; | |
int motorDelay = 800; | |
/* gripper */ | |
int inputPins[] = {2, 3, 4, 5}; | |
int duration = 3; | |
bool sequence[][4] = {{LOW, LOW, LOW, HIGH }, | |
{LOW, LOW, HIGH, HIGH}, | |
{LOW, LOW, HIGH, LOW }, | |
{LOW, HIGH, HIGH, LOW}, | |
{LOW, HIGH, LOW, LOW }, | |
{HIGH, HIGH, LOW, LOW}, | |
{HIGH, LOW, LOW, LOW }, | |
{HIGH, LOW, LOW, HIGH}}; | |
/* gripper end */ | |
void motorSola(int motor){ | |
digitalWrite(motor + 2, LOW); | |
digitalWrite(motor, LOW); | |
for (int index = 0; index < 200; index++) { | |
digitalWrite(motor + 1, HIGH); | |
delayMicroseconds(motorDelay); | |
digitalWrite(motor + 1, LOW); | |
delayMicroseconds(motorDelay); | |
} | |
} | |
void motorSaga(int motor){ | |
digitalWrite(motor + 2, LOW); | |
digitalWrite(motor, HIGH); | |
for (int index = 0; index < 200; index++) { | |
digitalWrite(motor + 1, HIGH); | |
delayMicroseconds(motorDelay); | |
digitalWrite(motor + 1, LOW); | |
delayMicroseconds(motorDelay); | |
} | |
} | |
void gripper(bool dir) { | |
int tempSecuenceNum = 0; | |
if (!dir) | |
tempSecuenceNum = 7; | |
for (int step = 0; step < 10; step++) { | |
for(int sequenceNum = tempSecuenceNum; (dir) ? (sequenceNum < 8) : (sequenceNum >= 0); (dir) ? sequenceNum++ : sequenceNum--){ | |
for(int inputCount = 0; inputCount < 4; inputCount++){ | |
digitalWrite(inputPins[inputCount], sequence[sequenceNum][inputCount]); | |
} | |
delay(duration); | |
} | |
} | |
} | |
void setup() | |
{ | |
pinMode(motor1, OUTPUT); | |
pinMode(motor1 + 1, OUTPUT); | |
pinMode(motor1 + 2, OUTPUT); | |
pinMode(motor2, OUTPUT); | |
pinMode(motor2 + 1, OUTPUT); | |
pinMode(motor2 + 2, OUTPUT); | |
pinMode(motor3, OUTPUT); | |
pinMode(motor3 + 1, OUTPUT); | |
pinMode(motor3 + 2, OUTPUT); | |
digitalWrite(motor1 + 2, HIGH); | |
digitalWrite(motor2 + 2, HIGH); | |
digitalWrite(motor3 + 2, HIGH); | |
/* esp wifi */ | |
Serial.begin(115200); //Seriport'u açıyoruz. Güncellediğimiz | |
//ESP modülünün baudRate değeri 115200 olduğu için bizde Seriport'u 115200 şeklinde seçiyoruz | |
Serial.println("AT"); //ESP modülümüz ile bağlantı kurulup kurulmadığını kontrol ediyoruz. | |
pinMode(13,OUTPUT); | |
delay(3000); //ESP ile iletişim için 3 saniye bekliyoruz. | |
if(Serial.find("OK")){ //esp modülü ile bağlantıyı kurabilmişsek modül "AT" komutuna "OK" komutu ile geri dönüş yapıyor. | |
Serial.println("AT+CWMODE=1"); //esp modülümüzün WiFi modunu STA şekline getiriyoruz. Bu mod ile modülümüz başka ağlara bağlanabilecek. | |
delay(2000); | |
String baglantiKomutu=String("AT+CWJAP=\"")+ag_ismi+"\",\""+ag_sifresi+"\""; | |
Serial.println(baglantiKomutu); | |
delay(5000); | |
} | |
Serial.print("AT+CIPMUX=1\r\n"); | |
delay(200); | |
Serial.print("AT+CIPSERVER=1,80\r\n"); | |
delay(1000); | |
/* end esp wifi */ | |
//gripper | |
for(int inputCount = 0; inputCount < 4; inputCount++) { | |
pinMode(inputPins[inputCount], OUTPUT); | |
} | |
} | |
void request(){ | |
String gelen =""; | |
char serialdenokunan; | |
while(Serial.available()>0){ | |
serialdenokunan = Serial.read(); | |
gelen +=serialdenokunan; | |
} | |
Serial.println(gelen); | |
if((gelen.indexOf(":GET /?motor=1")>1)){ | |
motorSola(motor2); | |
} | |
if((gelen.indexOf(":GET /?motor=2")>1)){ | |
motorSaga(motor2); | |
} | |
} | |
void loop() | |
{ | |
if(Serial.available() > 0) { | |
if(Serial.find("+IPD,")){ | |
String metin = "<h1>yeah</h1>"; | |
String cipsend = "AT+CIPSEND="; | |
cipsend +="0"; | |
cipsend +=","; | |
cipsend += metin.length(); | |
cipsend += "\r\n"; | |
Serial.print(cipsend); | |
delay(500); | |
Serial.println(metin); | |
request(); | |
Serial.println("AT+CIPCLOSE=0"); | |
} | |
/* if(data == '1') | |
motorSola(motor1); | |
else if(data == '2') | |
motorSaga(motor1); | |
else if(data == '3') | |
motorSola(motor2); | |
else if(data == '4') | |
motorSaga(motor2); | |
else if(data == '5') | |
motorSola(motor3); | |
else if(data == '6') | |
motorSaga(motor3); | |
else if(data == '7') // gripper turn on | |
gripper(true); | |
else if(data == '8') // gripper turn off | |
gripper(false);*/ | |
digitalWrite(motor1 + 2, HIGH); | |
digitalWrite(motor2 + 2, HIGH); | |
digitalWrite(motor3 + 2, HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment