Skip to content

Instantly share code, notes, and snippets.

@0atman
Created February 18, 2021 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0atman/5daaa313d537ad2973bccbb7348410b6 to your computer and use it in GitHub Desktop.
Save 0atman/5daaa313d537ad2973bccbb7348410b6 to your computer and use it in GitHub Desktop.
/*******************************************************************
A telegram bot for your Adafruit Feather M0 with KeyboardFeatherWing
Adapted from telegram code written by Brian Lough
*******************************************************************/
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <WiFi101.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_STMPE610.h>
#include <Adafruit_NeoPixel.h>
#include <BBQ10Keyboard.h>
#include <SD.h>
#include <WiFi101.h>
#include <UniversalTelegramBot.h>
#define STMPE_CS 6
#define TFT_CS 9
#define TFT_DC 10
#define SD_CS 5
#define NEOPIXEL_PIN 11
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000
// Wifi network station credentials
#define WIFI_SSID "YOUR SSID HERE"
#define WIFI_PASSWORD "YOUR PASSWORD HERE"
// Telegram b Token (Get from Botfather)
#define BOT_TOKEN "YOUR TOKEN HERE"
const unsigned long BOT_MTBS = 1000; // mean time between scan messages
WiFiSSLClient secured_client;
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
unsigned long bot_lasttime; // last time messages' scan has been done
Adafruit_STMPE610 ts(STMPE_CS);
Adafruit_ILI9341 tft(TFT_CS, TFT_DC);
Adafruit_NeoPixel pixels(1, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
BBQ10Keyboard keyboard;
File root;
void setup()
{
WiFi.setPins(8,7,4,2);
Wire.begin();
const bool sd = SD.begin(SD_CS);
tft.begin();
ts.begin();
pixels.begin();
pixels.setBrightness(30);
keyboard.begin();
keyboard.setBacklight(0.5f);
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.print("Hello FeatherWing!\n");
// attempt to connect to Wifi network:
tft.print("Connecting to Wifi SSID ");
tft.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
//secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
tft.print("\nWiFi connected. IP address: ");
tft.print(WiFi.localIP());
tft.print("\n");
tft.print("\n");
}
void loop()
{
if (millis() - bot_lasttime > BOT_MTBS)
{
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while (numNewMessages)
{
for (int i = 0; i < numNewMessages; i++)
{
tft.print(bot.messages[i].from_name);
tft.print("(");
tft.print(bot.messages[i].chat_id);
tft.print(")");
tft.print(" says: ");
tft.print(bot.messages[i].text);
tft.print("\n");
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, "");
}
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
bot_lasttime = millis();
}
}
@0atman
Copy link
Author

0atman commented Feb 18, 2021

50955075638_39e67ae8a8_o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment