Last active
September 29, 2016 02:38
-
-
Save e-Gizmo/2320be032857b40c8190859598889dec to your computer and use it in GitHub Desktop.
This file contains 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
//*********************************************// | |
// // | |
// MINIBOT_BT_CONTROLLED // | |
// // | |
// This demo program will controll the // | |
// minibot using android phone via bluetooth. // | |
// // | |
// Codes by: // | |
// e-Gizmo Mechatronix Central // | |
// Taft, Manila, Philippines // | |
// http://www.egizmo.com // | |
// May 15,2016 // | |
//*********************************************// | |
// INITIALIZATION: | |
#include <Servo.h> | |
byte INPUT_FROM_ANDROID_APP; | |
#define MOTOR_1_DIRECTION 8 // Motor control HIGH = FWD, LOW = BWD | |
#define MOTOR_1_SPEED 9 // Speed input | |
#define MOTOR_2_SPEED 10 // Speed input | |
#define MOTOR_2_DIRECTION 11 // Motor control HIGH = FWD, LOW = BWD | |
// INPUTS AND OUTPUTS | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(MOTOR_1_DIRECTION, OUTPUT); | |
pinMode(MOTOR_1_SPEED, OUTPUT); | |
pinMode(MOTOR_2_DIRECTION, OUTPUT); | |
pinMode(MOTOR_2_SPEED, OUTPUT); | |
} | |
// MAIN PROGRAM | |
void loop() { | |
if (Serial.available() > 0) { | |
INPUT_FROM_ANDROID_APP = Serial.read(); | |
Serial.println(INPUT_FROM_ANDROID_APP); | |
} | |
if (INPUT_FROM_ANDROID_APP==19){ | |
FORWARD(); | |
} | |
if (INPUT_FROM_ANDROID_APP==20){ | |
BACKWARD (); | |
} | |
if (INPUT_FROM_ANDROID_APP==22){ | |
SPIN_LEFT(); | |
} | |
if (INPUT_FROM_ANDROID_APP==21){ | |
SPIN_RIGHT(); | |
} | |
if (INPUT_FROM_ANDROID_APP==0){ | |
STOP (); | |
} | |
} | |
// PRERSET FUNCTIONS | |
void FORWARD() | |
{ | |
digitalWrite(MOTOR_1_DIRECTION,HIGH); | |
digitalWrite(MOTOR_2_DIRECTION,HIGH); | |
digitalWrite(MOTOR_1_SPEED, HIGH); | |
digitalWrite(10, HIGH); | |
delay(100); | |
} | |
void BACKWARD() | |
{ | |
digitalWrite(MOTOR_1_DIRECTION, LOW); | |
digitalWrite(MOTOR_1_SPEED, HIGH); | |
digitalWrite(MOTOR_2_SPEED, HIGH); | |
digitalWrite(MOTOR_2_DIRECTION, LOW); | |
delay(100); | |
} | |
void SPIN_LEFT() | |
{ | |
digitalWrite(MOTOR_1_DIRECTION, HIGH); | |
digitalWrite(MOTOR_1_SPEED, HIGH); | |
digitalWrite(MOTOR_2_SPEED, HIGH); | |
digitalWrite(MOTOR_2_DIRECTION, LOW); | |
delay(100); | |
} | |
void SPIN_RIGHT() | |
{ | |
digitalWrite(MOTOR_1_DIRECTION, LOW); | |
digitalWrite(MOTOR_1_SPEED, HIGH); | |
digitalWrite(MOTOR_2_SPEED, HIGH); | |
digitalWrite(MOTOR_2_DIRECTION, HIGH); | |
delay(100); | |
} | |
void STOP() | |
{ | |
analogWrite(MOTOR_1_SPEED, 0); | |
analogWrite(MOTOR_2_SPEED, 0); | |
} | |
// PROGRAM ENDS AND LOOP BACK FOREVER // PARZ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment