Last active
March 21, 2018 03:43
-
-
Save IdrisCytron/2e203641a05486d103ff6ce190859b91 to your computer and use it in GitHub Desktop.
Maker Uno - Build Your Own Mobile Robot and Control
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
/* | |
This example shows how to control Maker Uno mobile robot using BT remote app. | |
Tutorial page: | |
http://makeruno.com.my/build-your-own-mobile-robot-and-control/ | |
Original written by: | |
07/02/18 Asyraf (Intern), Cytron Technologies | |
Modified by: | |
27/02/18 Idris, Cytron Technologies | |
*/ | |
int in1 = 13; | |
int in2 = 12; | |
int in3 = 11; | |
int in4 = 10; | |
char data = 0; | |
void setup() | |
{ | |
pinMode(in1, OUTPUT); | |
pinMode(in2, OUTPUT); | |
pinMode(in3, OUTPUT); | |
pinMode(in4, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
if (Serial.available() > 0) { | |
data = Serial.read(); | |
if (data == '1') { | |
forward(); | |
} | |
if (data == '2') { | |
reverse(); | |
} | |
if (data == '3') { | |
left(); | |
} | |
if (data == '4') { | |
right(); | |
} | |
else { | |
stopp(); | |
} | |
} | |
} | |
void forward() | |
{ | |
digitalWrite(in1, HIGH); | |
digitalWrite(in2, LOW); | |
digitalWrite(in3, LOW); | |
digitalWrite(in4, HIGH); | |
delay(20); | |
} | |
void reverse() | |
{ | |
digitalWrite(in1, LOW); | |
digitalWrite(in2, HIGH); | |
digitalWrite(in3, HIGH); | |
digitalWrite(in4, LOW); | |
delay(20); | |
} | |
void left() | |
{ | |
digitalWrite(in1, LOW); | |
digitalWrite(in2, HIGH); | |
digitalWrite(in3, LOW); | |
digitalWrite(in4, HIGH); | |
delay(20); | |
} | |
void right() | |
{ | |
digitalWrite(in1, HIGH); | |
digitalWrite(in2, LOW); | |
digitalWrite(in3, HIGH); | |
digitalWrite(in4, LOW); | |
delay(20); | |
} | |
void stopp() | |
{ | |
digitalWrite(in1, LOW); | |
digitalWrite(in2, LOW); | |
digitalWrite(in3, LOW); | |
digitalWrite(in4, LOW); | |
delay(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment