Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include "esp32-hal-ledc.h"
- #include <Arduino.h>
- #include <Servo.h>
- Servo myservo;
- #define BLYNK_PRINT Serial
- #define BLYNK_USE_DIRECT_CONNECT
- #include <BlynkSimpleEsp32_BLE.h>
- #include <BLEDevice.h>
- #include <BLEServer.h>
- char auth[] = "";
- ///светодиоды
- #define LEDRED 19
- #define LEDGREEN 18
- #define LEDBLUE 23
- #define BOARDPIN 2
- #define LightPin 2
- #define LedPin 14
- int boardstate = 0;
- int butt;
- void LEDWRITE() {
- if (boardstate == 0) {
- ledcWrite(0, 255);
- ledcWrite(1, 255);
- ledcWrite(2, 0);
- }
- else if (boardstate == 2) {
- ledcWrite(0, 255);
- ledcWrite(1, 0);
- ledcWrite(2, 0);
- }
- else if ((boardstate == 4) || (boardstate == 5)) {
- ledcWrite(0, 0);
- ledcWrite(1, 0);
- ledcWrite(2, 255);
- }
- else if (boardstate == 6) {
- ledcWrite(0, 0);
- ledcWrite(1, 255);
- ledcWrite(2, 0);
- }
- else if (boardstate == 8) {
- ledcWrite(0, 255);
- ledcWrite(1, 255);
- ledcWrite(2, 255);
- }
- }
- ///пищалка
- #define movPin 2
- #define Sound 8
- void SIGNALIZACIA(){
- // int val = digitalRead(movPin);
- //Serial.println(val);
- // if (val){
- ledcWrite(4, 255);
- // }
- delay(500);
- ledcWrite(4, 0);
- }
- void Light(){
- int val=analogRead(LightPin);
- Serial.println(val);
- int ledPower=map(val, 0, 2000, 0, 255);
- ledcWrite(0, 255 - ledPower);
- ledcWrite(1, 255 - ledPower);
- ledcWrite(2, 255 - ledPower);
- }
- void setup() {
- Serial.begin(9600);
- myservo.attach(26);
- myservo.write(0);
- Blynk.begin(auth);
- pinMode(LEDRED, OUTPUT);
- pinMode(LEDGREEN, OUTPUT);
- pinMode(LEDBLUE, OUTPUT);
- pinMode(BOARDPIN, INPUT);
- pinMode(LightPin, INPUT);
- ledcSetup(0, 50, 8);
- ledcSetup(1, 50, 8);
- ledcSetup(2, 50, 8);
- ledcSetup(3, 50, 8);
- ledcSetup(4, 50, 8);
- ledcAttachPin(LEDRED, 0);
- ledcAttachPin(LEDGREEN, 1);
- ledcAttachPin(LEDBLUE, 2);
- ledcAttachPin(LedPin, 3);
- ledcAttachPin(Sound, 4);
- }
- void loop() {
- Blynk.run();
- myservo.write(butt);
- // клава
- boardstate = analogRead(BOARDPIN) / 205;
- if (boardstate != 9) {
- LEDWRITE();
- Serial.println(boardstate);
- }
- // освещение
- Light();
- // сигнализация
- if()
- SIGNALIZACIA();
- }
- //серво
- BLYNK_WRITE(V0) {
- butt = param.asInt();
- if(butt==1){
- butt=90;
- }else{
- butt=0;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement