How to build a Robot on an Arduino that can be controlled by a keyboard:
by J.B. WylzanHomodruino R2V1 |
/* ===============================================================
Project Homotronics: Robot controlled by a keyboard
Author: J. B. Wylzan with some help from the Arduino community
Website: http://www.ihackrobot.blogspot.com
Abstract: Control a robot via a keyboard.
================================================================== */
// Press the arrows on your keyboard to activate the robot
const int MLWF = 10;
const int MLBB = 9;
const int MRYF = 6;
const int MRRB = 5;
void setup() {
Serial.begin(9600);
pinMode(MLWF, OUTPUT);
pinMode(MLBB, OUTPUT);
pinMode(MRYF, OUTPUT);
pinMode(MRRB, OUTPUT);
}
void loop() {
if (Serial.available()>0) {
int data = Serial.read();
switch (data) {
case '1': // FWD
analogWrite(MLBB, 0);
analogWrite(MLWF, 255);
analogWrite(MRRB, 0);
analogWrite(MRYF, 255);
break;
case '2' : // BCK
analogWrite(MLBB, 255);
analogWrite(MLWF, 0);
analogWrite(MRRB, 255);
analogWrite(MRYF, 0);
break;
case '3' : // LFT
analogWrite(MLBB, 0);
analogWrite(MLWF, 255);
analogWrite(MRRB, 0);
analogWrite(MRYF, 0);
break;
case '4' : // RHT
analogWrite(MLBB, 0);
analogWrite(MLWF, 0);
analogWrite(MRRB, 0);
analogWrite(MRYF, 255);
break;
case '5': // STP
analogWrite(MLBB, 0);
analogWrite(MLWF, 0);
analogWrite(MRRB, 0);
analogWrite(MRYF, 0);
break;
default :
Serial.println("TYPE the correct NUMBER please");
break;
}
}
}
PROCESSING SKETCH:
import processing.serial.*;
Serial port;
String Ta= "HOMOTRONICS R2.4";
String Tb= "www.iHackLab.blogspot.com";
String Tc= "Click Here FIRST To START";
String T1= "FWD";
String T2= "RHT";
String T3= "LFT";
String T4= "BCK";
String T5= "STP";
char LETTER = 'S'; //STOP
void setup()
{
size(300,300);
println("Please press any ARROW key");
String portName = Serial.list()[10];
port = new Serial(this,"COM4",9600);
}
void draw()
{
background(149,201,255);
textSize(20);
fill (0,0,255);
text(Ta, 50, 70);
textSize(10);
fill (0,0,255);
text(Tb, 75, 82);
textSize(10);
fill (0,0,255);
text(Tc, 85, 270);
fill (0,0,255);
rect(155, 180, 55, 55, 7); //dwn
rect(85, 115, 55, 55,7); //bck
rect(85, 180, 55, 55,7); // lft
rect(155, 115, 55, 55,7); //rht
rect(120, 150, 55, 55,7); // stp
textSize (15);
fill (0,255,0);
text(T1, 97, 135); //FWD
text(T2, 170, 135); //RHT
text(T3, 98, 225); //LFT
text(T4, 170, 225); //BCK
text(T5, 137, 182); //STP
}
void keyPressed()
{
switch (keyCode) {
case UP:
port.write('1');
fill(33,255,33);
rect(85, 115, 55, 55,7);
break;
case DOWN:
port.write('2');
fill(33,255,33);
rect(155, 180, 55, 55, 7);
break;
case RIGHT:
port.write('3');
fill(33,255,33);
rect(155, 115, 55, 55,7);
break;
case LEFT:
port.write('4');
fill(33,255,33);
rect(85, 180, 55, 55,7);
break;
case 'S':
case 's':
port.write ('5');
fill(33,255,33);
rect(120, 150, 55, 55,7);
break;
default:
println("press the correct key please");
break;
}
}
Disclaimer: We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email.
Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®
==================================================================
Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.
==================================================================
Patent Pending. 2000 © ®
A L.A.W.S.I.N. Educational Production
No comments:
Post a Comment