#define BLEConnection 0
#define WIFIConnection 1
#define Connection BLEConnection
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/*#if Connection == WIFIConnection
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
#else
#include <BleKeyboard.h>
#endif*/
/*#if Connection == WIFIConnection
// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
// Initialize Telegram BOT
#define BOTtoken "XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
#define CHAT_ID "XXXXXXXXXX"
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
#else
BleKeyboard bleKeyboard;
#endif*/
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
uint8_t number;
uint8_t count;
bool tono ;
#if Connection == WIFIConnection
String numberS;
String chat_id=CHAT_ID;
#endif
char numberC;
void setup() {
Serial.begin(115200);
pinMode(27, INPUT);//3
pinMode(25, INPUT); //4
pinMode(26, INPUT);//5
pinMode(34, INPUT);//6
pinMode(35, INPUT);//7
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
/*#if Connection == WIFIConnection
// Connect to Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
#else
Serial.println("Starting BLE work!");
bleKeyboard.begin();
#endif*/
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.cp437(true); // Use full 256 char 'Code Page 437' font
}
void loop() {
tono = digitalRead(27);
if(tono == HIGH) /* If new pin pressed */
{
display.setCursor(0, 0);
display.println("marcando");
delay(250);
number = ( 0x00 | (digitalRead(35)<<0) | (digitalRead(34)<<1) | (digitalRead(26)<<2) | (digitalRead(25)<<3) );
if(number>0 && number <=9)
numberC=number+'0';// ASCII convertion
else if(number==0x0A) numberC='0';
else if(number==0x0B) numberC='*';
else numberC='#';
#if Connection == BLEConnection
// if(bleKeyboard.isConnected()) {
Serial.println("Sending dialed number...");
// bleKeyboard.print(numberC);
// }
#endif
display.fillRect(0, 20, 5, 7, SSD1306_BLACK);
display.setCursor(0, 20);
display.println(numberC);
display.display();
/* switch (number)
{
case 0x01:
Serial.println("Pin Pressed : 1");
break;
case 0x02:
Serial.println("Pin Pressed : 2");
break;
case 0x03:
Serial.println("Pin Pressed : 3");
break;
case 0x04:
Serial.println("Pin Pressed : 4");
break;
case 0x05:
Serial.println("Pin Pressed : 5");
break;
case 0x06:
Serial.println("Pin Pressed : 6");
break;
case 7:
Serial.println("Pin Pressed : 7");
break;
case 0x08:
Serial.println("Pin Pressed : 8");
break;
case 0x09:
Serial.println("Pin Pressed : 9");
break;
case 0x0A:
Serial.println("Pin Pressed : 0");
break;
case 0x0B:
Serial.println("Pin Pressed : *");
break;
case 0x0C:
Serial.println("Pin Pressed : #");
break;
}*/
#if Connection == WIFIConnection
numberS+=numberC;
#endif
count++;
if(count==10)
{
count=0;
#if Connection == WIFIConnection
bot.sendMessage(chat_id, numberS.c_str(), "");
numberS="";
#else
Serial.println("Sending Enter key...");
//bleKeyboard.write(KEY_RETURN);
display.fillRect(0, 20, 5, 7, SSD1306_BLACK);
display.setCursor(5, 20);
display.println("ENTER");
display.display();
delay(5000);
display.clearDisplay();
#endif
}
}
}