Informe Practica Bluetooth
Informe Practica Bluetooth
TRABAJO A REALIZAR:
Página 1 de 6
CÓDIGO IMPLEMENTADO
#include <BluetoothSerial.h>
BluetoothSerial bluetooth_osm;
#define RGB_LED_RED_DO 13
#define RGB_LED_GREEN_DO 5
#define RGB_LED_BLUE_DO 23
#define POTENCIOMETER_AI 34
#define PERIOD_SEND_BLUETOOTH_REQUEST 20
#define PERIOD_RGB_LED_RED_DO 2700
#define PERIOD_RGB_LED_BLUE_DO 200
#define PERIOD_POTENCIOMETER_PRINF_VALUE 1000
#define ANALOG_RESOLUTION 11
void setup() {
Serial.begin(115200);
bluetooth_osm.begin("ESP32_osm"); //Bluetooth device name
analogReadResolution(ANALOG_RESOLUTION);
pinMode(RGB_LED_RED_DO, OUTPUT);
pinMode(RGB_LED_GREEN_DO, OUTPUT);
pinMode(RGB_LED_BLUE_DO, OUTPUT);
void loop() {
send_bluetooth_request(PERIOD_SEND_BLUETOOTH_REQUEST);
Página 2 de 6
static uint32_t last_execution = 0;
uint32_t current_time = 0;
uint32_t time_diference = 0;
current_time = millis();
time_diference = current_time - last_execution;
if (bluetooth_osm.available()) {
send_caracter_bt = bluetooth_osm.read();
switch (send_caracter_bt){
case 'a':
digitalWrite(RGB_LED_GREEN_DO, HIGH);
break;
case 'b':
digitalWrite(RGB_LED_GREEN_DO, LOW);
break;
case 'c':
blink_red_rgb_led_satus = true;
break;
case 'd':
blink_red_rgb_led_satus = false;
digitalWrite(RGB_LED_RED_DO, LOW);
break;
case 'e':
blink_blue_rgb_led_satus = true;
break;
case 'f':
blink_blue_rgb_led_satus = false;
digitalWrite(RGB_LED_BLUE_DO, LOW);
break;
}
potenciometre_printf_value(PERIOD_POTENCIOMETER_PRINF_VALUE);
}
Página 3 de 6
if(true == blink_red_rgb_led_satus){
blink_rgb_red_led(PERIOD_RGB_LED_RED_DO);
if(true == blink_blue_rgb_led_satus){
blink_rgb_blue_led(RGB_LED_BLUE_DO);
current_time = millis();
time_diference = current_time - last_execution;
if(time_diference >= period_rgb_red_led){
last_execution = current_time;
led_status = !led_status;
digitalWrite(RGB_LED_RED_DO, led_status);
Serial.println("Led_rojo_encendido");
}
}
current_time = millis();
time_diference = current_time - last_execution;
if(time_diference >= period_rgb_blue_led){
last_execution = current_time;
led_status = !led_status;
digitalWrite(RGB_LED_BLUE_DO, led_status);
Página 4 de 6
Serial.println("Led_azul_encendido");
}
}
uint32_t current_time = 0;
static uint32_t last_execution = 0;
uint32_t time_difference = 0;
int16_t potentiometer_adc = 0;
current_time = millis();
time_difference = uint32_t(current_time - last_execution);
potentiometer_adc = analogRead(POTENCIOMETER_AI);
bluetooth_osm.print(voltage_potentiometer);
bluetooth_osm.println("V");
}
}
Página 5 de 6
CONCLUSIÓN
En esta práctica se ha hecho uso de la librería BluetoothSerial.h para poder usar las funciones por de
bluetooth. Se ha hecho uso de la función bluetooth_osm.available() para popder comunicar vía bluetooth. Se
ha hecho de la función bluetooth_osm.begin("ESP32_osm") para darle nombre a la placa esp32. Se ha hecho
uso de la función bluetooth_osm.read() para leer el puerto bluetooth.
En esta práctica he aprendido a hacer la comunicación vía bluetooth. He aprendido ha usar las funciones para
la lectura y escritura de la comunicación vía bluetooth. He aprendido a comunicar una placa de Arduino con
un móvil vía bluetooth.
Página 6 de 6