/* ===============================================================
Project Homotronics: Robot controlled by a keyboard
Author: J. B. Wylzan with libraries from the Arduino website
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;
}
}
"Humans can't think of something, without associating it with something."
~ 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