#include "pitches.h" int motor1Pin1 = 12; // pin 2 on L293D IC int motor1Pin2 = 11; // pin 7 on L293D IC int motor2Pin1 = 10; // pin 10 on L293D IC int motor2Pin2 = 9; // pin 15 on L293D IC int right = 5; //turet right int left = 4; // turet left int up = 3; //turet up down int fire = 2; // fire int state; void setup() { // sets the pins as outputs: pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); //pinMode(enable1Pin, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); pinMode(up, OUTPUT); pinMode(fire, OUTPUT); pinMode(right, OUTPUT); pinMode(left, OUTPUT); Serial.begin(9600); } void loop() { //if some date is sent, reads it and saves in state if(Serial.available() > 0){ state = Serial.read(); } // forward if (state == 'w') { digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); } // left else if (state == 'e') { digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); } // right else if (state == 'q') { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); } // up left else if (state == 'a') { digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); } // up right else if (state == 's') { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); } // down left else if (state == 'z') { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); } // down right else if (state == 'c') { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); } // backward else if (state == 'd') { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); } // turet right else if (state == 'o') { digitalWrite(right, HIGH); digitalWrite(left, LOW); } // turet left else if (state == 'p') { digitalWrite(right, LOW); digitalWrite(left, HIGH); } // turet up down else if (state == 'k') { digitalWrite(up, HIGH); } // fire else if (state == 'f') { digitalWrite(fire, HIGH); } //horn else if (state == 'h') { tone(13, NOTE_C4); } // Stop else { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); digitalWrite(up, LOW); digitalWrite(fire, LOW); digitalWrite(right, LOW); digitalWrite(left, LOW); noTone(13); } delay(100); }