#include <Arduino.h>
#include <TFT_eSPI.h>
#include <SPI.h>
#include <Wire.h>
#include <Button2.h>
#include "esp_adc_cal.h"
#include <BleMouse.h>
#ifndef TFT_DISPOFF
#define TFT_DISPOFF 0x28
#endif
#ifndef TFT_SLPIN
#define TFT_SLPIN 0x10
#endif
#define TFT_MOSI 19
#define TFT_SCLK 18
#define TFT_BL 4
#define ADC_EN 14
#define ADC_PIN 34
#define BUTTON_1 35
#define BUTTON_2 0
TFT_eSPI tft = TFT_eSPI(TFT_HEIGHT, TFT_WIDTH);
BleMouse bleMouse;
boolean isConn = false;
int touch_sensor_value_T0 =0;
int touch_sensor_value_T1 =0;
int tsv_ENTER =0;
int tsv_SELECT =0;
int tsv_CANCEL =0;
int tsv_LEFT =0;
int touch_sensor_value_T6 =0;
int tsv_DOWN =0;
int tsv_RIGHT =0;
int touch_sensor_value_T9 =0;
void espDelay(int ms)
{
esp_sleep_enable_timer_wakeup(ms * 1000);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH,ESP_PD_OPTION_ON);
esp_light_sleep_start();
}
void setup()
{
Serial.begin(9600);
Serial.println("Start");
Serial.println("Starting BLE work!");
bleMouse.begin();
tft.init();
tft.setRotation(2);
tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);
tft.setTextColor(TFT_WHITE);
tft.setCursor(0, 0);
tft.setTextDatum(TL_DATUM);
tft.drawString("Not connected", 70 , tft.height() / 2 );
if (TFT_BL > 0) {
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, TFT_BACKLIGHT_ON);
}
espDelay(5000);
}
void loop()
{
tsv_ENTER = touchRead(T2);
tsv_SELECT = touchRead(T3);
tsv_CANCEL = touchRead(T4);
tsv_LEFT = touchRead(T5);
tsv_DOWN = touchRead(T7);
tsv_RIGHT = touchRead(T8);
if( bleMouse.isConnected() && !isConn) {
isConn = true;
tft.fillScreen(TFT_BLACK);
tft.drawString("Connected", 70 , tft.height() / 2 );
} else if(!bleMouse.isConnected() && isConn) {
isConn = false;
tft.fillScreen(TFT_BLACK);
tft.drawString("Not connected", 70 , tft.height() / 2 );
}
if (isConn)
{
if(tsv_LEFT > 5 && tsv_LEFT < 30){bleMouse.move(-2, 0, 0);}
if(tsv_RIGHT > 5 && tsv_RIGHT < 30){bleMouse.move( 2, 0, 0);}
if(tsv_DOWN > 5 && tsv_DOWN < 30){bleMouse.move( 0, 2, 0);}
}
delay(20);
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.