Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int A1A = 3;//define pin 3 for A1A
- int A1B = 5;//define pin 5 for A1B
- int B1A = 4;//define pin 4 for B1A
- int B1B = 6;//define pin 6 for B1B
- int PW = 120; //power motor
- #include <SoftwareSerial.h>// import the serial library
- SoftwareSerial Genotronex(10,11); // D10 -> TX, D11 -> RX
- int BluetoothData;
- void setup() {
- Genotronex.begin(9600);
- Serial.begin(9600);
- pinMode(B1A,OUTPUT);// define pin as output
- pinMode(B1B,OUTPUT);
- pinMode(A1A,OUTPUT);
- pinMode(A1B,OUTPUT);
- motorA('O');
- delay(500);
- }
- void loop() {
- if (Genotronex.available()){
- BluetoothData=Genotronex.read();
- Serial.println(BluetoothData);}
- if ( BluetoothData == 50) motorB('L');// Turn motor B to LEFT;
- if ( BluetoothData == 51) motorB('R');// Turn motor B to RIGHT;
- if ( BluetoothData == 49) motorB('O');// Turn motor B to OFF;
- if ( BluetoothData == 52) motorA('O');// Turn motor A to OFF;
- if ( BluetoothData == 53) motorA('S');// Turn motor A to SLOW;
- if ( BluetoothData == 54) motorA('R');// Turn motor A to FAST;
- if ( BluetoothData == 55) {if (A1A == 3) {A1A = 5; A1B = 3;} else {A1A = 3; A1B = 5;}} // Reverse motor A;
- delay(5);
- }
- void motorA(char d)
- {
- if(d =='R'){ PW = 180;
- digitalWrite(A1A,LOW);
- analogWrite(A1B,PW);
- }else if (d =='S') { PW = 120;
- digitalWrite(A1A,LOW);
- analogWrite(A1B,PW);
- }else{
- analogWrite(A1A,0);
- analogWrite(A1B,0);
- }
- }// motorA end
- void motorB(char d)
- {
- if(d =='R'){
- digitalWrite(B1A,LOW);
- digitalWrite(B1B,HIGH);
- analogWrite(A1B,PW+10); //more power
- }else if(d =='L'){
- digitalWrite(B1A,HIGH);
- digitalWrite(B1B,LOW);
- analogWrite(A1B,PW+10); //more power
- }else{
- // Turn motor OFF
- digitalWrite(B1A,LOW);
- digitalWrite(B1B,LOW);
- }
- }// motorB end
Advertisement
Add Comment
Please, Sign In to add comment