#include <FastBot.h>
#include <WiFi.h>
#define BOT_TOKEN "7473353219:AAHT5ffDFFXL17K9TKXbXyCisROCPDzBngg"
#define USER_ID "1971290668"
FastBot bot(BOT_TOKEN);
const int ledPins[] = {2, 4, 16, 17, 5, 18, 19, 21};
const int buzzerPin = 23;
const int button1Pin = 26;
const int button2Pin = 27;
int currentLed;
bool direction = false;
int speed = 1000;
void setup() {
Serial.begin(115200);
for (int i = 0; i < 8; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(buzzerPin, OUTPUT);
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
connectWiFi();
bot.setChatID(USER_ID);
bot.sendMessage("Бот запущений!");
bot.attach(newMsg);
run();
}
void loop() {
bot.tick();
}
void run() {
Serial.println("run");
if (direction) {
Serial.println("direction true");
for (currentLed = 0; currentLed < 8; currentLed++) {
Serial.println(currentLed, ledPins[currentLed]);
digitalWrite(ledPins[currentLed], HIGH);
delay(speed);
digitalWrite(ledPins[currentLed], LOW);
}
} else {
Serial.println("direction false");
for (currentLed = 7; currentLed >= 0; currentLed--) {
Serial.println(currentLed, ledPins[currentLed]);
digitalWrite(ledPins[currentLed], HIGH);
delay(speed);
digitalWrite(ledPins[currentLed], LOW);
}
}
delay(100);
tone(buzzerPin, 1000, 300);
}
void newMsg(FB_msg& msg) {
if (msg.text == "/switch") {
direction = !direction;
bot.sendMessage("ok " + String(direction), msg.chatID);
run();
}
}
void connectWiFi() {
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.print("Connected");
}