You Reply: The red one is a bluetooth mate gold.
The code for the uno is something like:
[code]
#include <SoftwareSerial.h>
int pin1 = 4;
int pin2 = 5;
int pin3 = 6;
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
int i;
char command;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
for(i=pin1;i<=pin3;i++){
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
Serial.begin(9600);
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600*/
}
void loop()
{
if(bluetooth.available()){
command = bluetooth.read();
bluetooth.println(command,DEC);
if(command == '0')
for(i=pin1;i<=pin3;i++)
digitalWrite(i, LOW);
if(command == '1')
for(i=pin1;i<=pin3;i++)
digitalWrite(i, HIGH);
if(command == '2'){
digitalWrite(pin3, HIGH);
for(i=pin1;i<=pin2;i++)
digitalWrite(i, LOW);
}
if(command == '3'){
digitalWrite(pin1, HIGH);
for(i=pin2;i<=pin3;i++)
digitalWrite(i, LOW);
}
if(command == '4'){
digitalWrite(pin1, LOW);
digitalWrite(pin2, HIGH);
digitalWrite(pin3, LOW);
}
}
}
[/code]
And the Romeo code is something like:
[code] int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 4; //M1 Direction Control
int M2 = 7; //M1 Direction Control
void stop(void) //Stop
{
digitalWrite(E1,0);
digitalWrite(M1,LOW);
digitalWrite(E2,0);
digitalWrite(M2,LOW);
}
void advance(char a,char b) //Move forward
{
analogWrite (E1,a); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void back_off (char a,char b) //Move backward
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void turn_L (char a,char b) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void turn_R (char a,char b) //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void setup(void)
{
int i;
for(i=4;i<=7;i++)
pinMode(i, OUTPUT);
Serial.begin(9600); //Set Baud Rate
Serial.println("Run keyboard control");
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
pinMode(2,INPUT);
pinMode(3,INPUT);
}
//String Buttons[17] = {
// "J2","J1",NULL,"S2","S1","UP","LEFT","DOWN","RIGHT","1","4","2","3","RZ1","RZ2","LZ1","LZ2"};
// // Buttons Nmes
void loop(void)
{
if(Serial.available()){
// String n = Buttons();
char n=Serial.read();
if(n != -1)
{
switch(n)
{
case '6'://Move Forward
advance (255,255); //move forward in max speed
break;
case '8'://Move Backward
back_off (255,255); //move back in max speed
break;
case '7'://Turn Left
turn_L (100,100);
break;
case '9'://Turn Right
turn_R (100,100);
break;
case '1':
stop();
break;
}
}
else stop();
}
}
[/code]