Paso 4: Modificar para hacerlo puede controlar el brazo mecánico por Bluetooth
Por supuesto, no utilice estas funciones para controlar el LED. Así que modificamos para hacerla puede controlar el brazo mecánico por Bluetooth. Ahora lista funciones acerca de la clase de ElecfreaksCar:
getRoll(); devuelve datos de rodillo, de 0 a 250
getPitch(); devolverá los datos de campo, de 0 a 250 setFun (void (* Function)()); se ejecutará la sentencia de la función cuando el usuario presiona el botón de la aplicación.
Este es el programa sobre el brazo mecánico bruja está escrita por mí. Y usted puede cambiarlo para crear programa de brazo mecánico.
<p>#include<br>"ElecfreaksCar.h"</p><p>#include "Servo.h</p><p>ElecfreaksCar BluetoothModule; //define<br>a variable of class of ElecfreaksCar which is named BluetoothModule</p><p>Servo Servo_Roll; //This is a servo which to turn direction</p><p>Servo Servo_Distance; //This is a servo which is to control the distance between the machanical hand and object.</p><p>Servo Servo_Catch; //THis is a servo which is to control the manchanical hand to catch or let go. </p><p>float<br>P=125.00; //This is value of pitch. This value is middle value when the rocker in the middle</p><p>float R=125.00; //This is value of roll. This value is middle value when the rocker in the middle</p><p>unsigned char Flag_Catch = 0; //This is a flag about if the machanical hand catch or not</p><p>void<br>Button() //This function is to be run when user touch the button of APP</p><p>{</p><p> if(Flag_Catch == 1)</p><p> {</p><p> Servo_Catch.write(0); //Catch</p><p> Flag_Catch = 0;</p><p> }</p><p> else</p><p> {</p><p> Servo_Catch.write(90); //let go</p><p> Flag_Catch = 1;</p><p> }</p><p>}</p><p>void<br>setup()</p><p>{</p><p> Serial.begin(115200); //baud rate</p><p> BluetoothModule.setFun(Button); //The arduino will run the function which is in the parameter. In here, it will run the function of "Button"</p><p> Servo_Catch.attach(2); //the servo of catch is connected with pin D2</p><p> Servo_Distance.attach(4); //the servo of controlling distance between machanical hand and object is connected with pin D4</p><p> Servo_Roll.attach(5); //the servo of controlling direction is connected with pin D5</p><p>}</p><p>void loop()</p><p>{</p><p> while(Serial.available()) //if there is any data come from bluetooth, it will into the function of while</p><p> {</p><p> uint8_t c = Serial.read(); //read the data of serial com</p><p> BluetoothModule.recievedData(&c, 1); //recieve the data</p><p> P=(float)BluetoothModule.getPitch(); //get the data of pitch</p><p> R=(float)BluetoothModule.getRoll(); //get the data of roll</p><p>P = P *<br>0.72; //This is important. the value of the rocker of APP is from 0 to 250, But the degree of servo is from 0 degree to 180 degrees. </p><p> //So we must make the value of pitch to multiplicative (180/250).</p><p> R = R * 0.72; //the same as pitch</p><p> }</p><p> Servo_Distance.write((int)P); //make the servo to run the degree</p><p> Servo_Roll.write((int)R); </p><p>}</p>
ElecfreaksCar
Descargar la aplicación:
http://www.elecfreaks.com/wiki/index.php?title=Blu...
Descargar bibliotecas:
http://www.elecfreaks.com/eStore/download/Librarie...
Más proyectos de electrónica DIY, visítenos en: http://www.elecfreaks.com/page/1