En esta ocasion vamos a mover un cubo que esta en Unity 3D por medio del Arduino Uno.
Procedimiento:
1.-Hacemos el programa del Arduino Uno,que consiste en leer el estado de un pulso externo(Button).
y enviarlo por medio de la comunicacion serial RS232 a la PC.
codigo del Arduino:
/***************************************************************/
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.println(buttonState);//Send '1'
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
Serial.println(buttonState);//Send '0'
}
delay(150);
}
/**********************************************************/
Link-->Download_Arduino_Button
/**********************************************************/
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.println(buttonState);//Send '1'
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
Serial.println(buttonState);//Send '0'
}
delay(150);
}
/**********************************************************/
Link-->Download_Arduino_Button
/**********************************************************/
2.-Creamos el cubo en Unity 3D y activamos su comunicacion RS232 para poder leer los datos que son enviados desde el Arduino. Seleccionamos el COMx correspodiente al Arduino Uno.
Luego le damos al boton Start y nos saldra el mensaje de comenzar.
Programa del Unity 3D.
/**********************************************************/
link-->Download_Cubo_Arduino
/**********************************************************/
/**********************************************************/
link-->Download_Cubo_Arduino
/**********************************************************/
3.-Con cada pulso('1') que le realizamos al arduino(Button) el cubo se eleva.