Commit 9072634c by satsob

Uuendused

parent 9a17b0e3
Showing with 215 additions and 0 deletions
#include <SoftwareSerial.h>
#include <SoftwareSerial.h>
//#include <SPI.h>
//Blue RXD - TXD - 3
//Green TXD - RXD - 2
SoftwareSerial BTserial(2, 3); // RX | TX
char receivedBluetValue;
int motorValue = 0;
int d7 = 5;//43; // Yellow, front wheel 2 - Forward
int d2 = 6;//41; // Red, front wheel 2 - Backward
int d8 = 7;//47; // Green, back wheel 2 - Forward
int d1 = 8;//45; // Orange, back wheel 2 - Backward
int d6 = 9;//40; // White, front wheel 1 - Backward
int d5 = 10;//42; // Black, front wheel 1 - Forward
int d4 = 11;//44; // Grey, back wheel 1 - Backward
int d3 = 12;//46; // Dark Greenish, back wheel 1 - Forward
//int speedN1 = ;
//int speedS1 = ;
//int speedN2 = ;
//int speedS2 = ;
void setup() {
Serial.begin(9600); // Default communication rate of the Bluetooth module
// HC-05 default serial speed for AT mode is 38400. 9600 works here!
BTserial.begin(9600);
//Serial.println("AT+PAIR=A0CB,FD,DDE2F9,20");
//Declaring the pin modes
pinMode(d7, OUTPUT); // Yellow
pinMode(d2, OUTPUT); // Red
pinMode(d8, OUTPUT); // Green
pinMode(d1, OUTPUT); // Orange
pinMode(d3, OUTPUT); // Dark Greenish
pinMode(d4, OUTPUT); // Grey
pinMode(d5, OUTPUT); // Black
pinMode(d6, OUTPUT); // White
//pinMode(speedN, OUTPUT);
//pinMode(speedS, OUTPUT);
}
void loop() {
//Serial.println("AT+PAIR=A0CB,FD,DDE2F9,20"); //To pair Bluetooth device with an address
//of A0:CB:FD:DD:E2:F9). 20 is the connection time limit.
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTserial.available())
{
receivedBluetValue = BTserial.read();
Serial.write(receivedBluetValue);
//Serial.println(receivedBluetValue);
//Serial.println("ON");
}
//else
// Serial.println("OFF");
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
{
receivedBluetValue = Serial.read();
//Serial.println(receivedBluetValue);
BTserial.write(receivedBluetValue);
}
//motorValue'd on suured tähed ASCII kümnendkoodis.
//Näiteks "Forward" on F ehk 70 10nd süsteemis.
motorValue = receivedBluetValue;
//Serial.println(motorValue);
if(motorValue == 70){
Forward();
delay(100);
Serial.println("Forward");}
else if(motorValue == 66){
Backward();
delay(100);
Serial.println("Backward");}
else if(motorValue == 82){
Right();
delay(100);
Serial.println("Right");}
else if(motorValue == 76){
Left();
delay(100);
Serial.println("Left");}
else if(motorValue == 73){
ForwardRight();
delay(100);
Serial.println("ForwardRight");}
else if(motorValue == 71){
ForwardLeft();
delay(100);
Serial.println("ForwardLeft");}
else if(motorValue == 74){
BackwardRight();
delay(100);
Serial.println("BackwardRight");}
else if(motorValue == 72){
BackwardLeft();
delay(100);
Serial.println("BackwardLeft");}
else {
Stop();
delay(100);
motorValue = 0;
}
}
void Forward() {
digitalWrite(d8, LOW);
digitalWrite(d1, HIGH);
//analogWrite(speedS,150);
digitalWrite(d7, LOW);
digitalWrite(d2, HIGH);
//analogWrite(speedN,150);
digitalWrite(d3, LOW);
digitalWrite(d4, HIGH);
digitalWrite(d5, LOW);
digitalWrite(d6, HIGH);
}
void Backward() {
digitalWrite(d8, HIGH);
digitalWrite(d1, LOW);
//analogWrite(speedS,150);
digitalWrite(d7, HIGH);
digitalWrite(d2, LOW);
//analogWrite(speedN,150);
digitalWrite(d3, HIGH);
digitalWrite(d4, LOW);
digitalWrite(d5, HIGH);
digitalWrite(d6, LOW);
}
void Right() {
digitalWrite(d8, LOW);
digitalWrite(d1, LOW);
//analogWrite(speedS,150);
digitalWrite(d7, LOW);
digitalWrite(d2, LOW);
//analogWrite(speedN,150);
digitalWrite(d3, LOW);
digitalWrite(d4, HIGH);
digitalWrite(d5, LOW);
digitalWrite(d6, HIGH);
}
void Left() {
digitalWrite(d8, LOW);
digitalWrite(d1, HIGH);
//analogWrite(speedS,150);
digitalWrite(d7, LOW);
digitalWrite(d2, HIGH);
//analogWrite(speedN,150);
digitalWrite(d3, LOW);
digitalWrite(d4, LOW);
digitalWrite(d5, LOW);
digitalWrite(d6, LOW);
}
void ForwardRight() {
digitalWrite(d8, LOW);
digitalWrite(d1, HIGH);
digitalWrite(d7, LOW);
digitalWrite(d2, LOW);
digitalWrite(d3, LOW);
digitalWrite(d4, HIGH);
digitalWrite(d5, LOW);
digitalWrite(d6, HIGH);
}
void ForwardLeft() {
digitalWrite(d8, LOW);
digitalWrite(d1, LOW);
digitalWrite(d7, LOW);
digitalWrite(d2, HIGH);
digitalWrite(d3, LOW);
digitalWrite(d4, HIGH);
digitalWrite(d5, LOW);
digitalWrite(d6, HIGH);
}
void BackwardRight() {
digitalWrite(d8, HIGH);
digitalWrite(d1, LOW);
digitalWrite(d7, LOW);
digitalWrite(d2, LOW);
digitalWrite(d3, HIGH);
digitalWrite(d4, LOW);
digitalWrite(d5, HIGH);
digitalWrite(d6, LOW);
}
void BackwardLeft() {
digitalWrite(d8, LOW);
digitalWrite(d1, LOW);
digitalWrite(d7, HIGH);
digitalWrite(d2, LOW);
digitalWrite(d3, HIGH);
digitalWrite(d4, LOW);
digitalWrite(d5, HIGH);
digitalWrite(d6, LOW);
}
void Stop() {
digitalWrite(d8, LOW);
digitalWrite(d1, LOW);
//analogWrite(speedS,0);
digitalWrite(d7, LOW);
digitalWrite(d2, LOW);
//analogWrite(speedN,0);
digitalWrite(d3, LOW);
digitalWrite(d4, LOW);
digitalWrite(d5, LOW);
digitalWrite(d6, LOW);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment