Project Homotronics: Robot controlled by bluetooth
Author: J. B. Wylzan with libraries from the Arduino website
Website: http://www.iHackRobot.blogspot.com
Abstract: Control a robot via bluetooth.
================================================================== */
int IN1 = 6;
int IN2 = 5;
int ENA = 4;
int mode;
int key=0;
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
//pinMode(ENA, OUTPUT);
// digitalWrite(ENA, HIGH);
Serial.begin(9600);
}
void loop() {
if(Serial.available() > 0){
mode = Serial.read();
key=0;
}
if (mode == '0') {
analogWrite(IN1, 0);
analogWrite(IN2, 0);
if(key== 0){
Serial.println("Pressed 0");
Serial.println("Stopping");
Serial.println("Blinking Red");
key=1;
}
}
else if (mode == '1') {
analogWrite(IN1, 0);
analogWrite(IN2, 255);
if(key== 0){
Serial.println("Pressed 1");
Serial.println("Moving forward");
Serial.println("Blinking Green");
key=1;
}
}
else if (mode == '2') {
analogWrite(IN1, 255);
analogWrite(IN2, 0);
if(key== 0){
Serial.println("Pressed 2");
Serial.println("Moving reverse");
Serial.println("Blinking Yellow");
key=1;
}
}
}
/* ================================================================== */
*** Warning ***
1. Remove the RX and TX cables when uploading the sketch.
2. Connect TX to RX and RX to TX.
"Everything has only two options: this or that."
~ Joey Lawsin
==================================================================
NOTICE: Articles on this site are composed on random
thoughts. The transcript may not be in its final form. It maybe
edited, updated or even revised in the future based on the outcomes of the author's experiments.
==================================================================
Patent Pending. 2000 © ®
No comments:
Post a Comment