Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include "esp32-hal-ledc.h"
  3. #include <Arduino.h>
  4. #include <Servo.h>
  5.  
  6. Servo myservo;
  7.  
  8. #define BLYNK_PRINT Serial
  9.  
  10. #define BLYNK_USE_DIRECT_CONNECT
  11.  
  12. #include <BlynkSimpleEsp32_BLE.h>
  13. #include <BLEDevice.h>
  14. #include <BLEServer.h>
  15. char auth[] = "";
  16. ///светодиоды
  17. #define LEDRED 19
  18. #define LEDGREEN 18
  19. #define LEDBLUE 23
  20. #define BOARDPIN 2
  21. #define LightPin 2
  22. #define LedPin 14
  23.  
  24. int boardstate = 0;
  25. int butt;
  26. void LEDWRITE() {
  27. if (boardstate == 0) {
  28. ledcWrite(0, 255);
  29. ledcWrite(1, 255);
  30. ledcWrite(2, 0);
  31. }
  32. else if (boardstate == 2) {
  33. ledcWrite(0, 255);
  34. ledcWrite(1, 0);
  35. ledcWrite(2, 0);
  36. }
  37. else if ((boardstate == 4) || (boardstate == 5)) {
  38. ledcWrite(0, 0);
  39. ledcWrite(1, 0);
  40. ledcWrite(2, 255);
  41. }
  42. else if (boardstate == 6) {
  43. ledcWrite(0, 0);
  44. ledcWrite(1, 255);
  45. ledcWrite(2, 0);
  46. }
  47. else if (boardstate == 8) {
  48. ledcWrite(0, 255);
  49. ledcWrite(1, 255);
  50. ledcWrite(2, 255);
  51. }
  52. }
  53.  
  54. ///пищалка
  55. #define movPin 2
  56. #define Sound 8
  57.  
  58. void SIGNALIZACIA(){
  59. // int val = digitalRead(movPin);
  60. //Serial.println(val);
  61. // if (val){
  62. ledcWrite(4, 255);
  63. // }
  64. delay(500);
  65. ledcWrite(4, 0);
  66. }
  67.  
  68.  
  69. void Light(){
  70. int val=analogRead(LightPin);
  71. Serial.println(val);
  72. int ledPower=map(val, 0, 2000, 0, 255);
  73. ledcWrite(0, 255 - ledPower);
  74. ledcWrite(1, 255 - ledPower);
  75. ledcWrite(2, 255 - ledPower);
  76. }
  77.  
  78. void setup() {
  79. Serial.begin(9600);
  80. myservo.attach(26);
  81. myservo.write(0);
  82. Blynk.begin(auth);
  83. pinMode(LEDRED, OUTPUT);
  84. pinMode(LEDGREEN, OUTPUT);
  85. pinMode(LEDBLUE, OUTPUT);
  86. pinMode(BOARDPIN, INPUT);
  87. pinMode(LightPin, INPUT);
  88. ledcSetup(0, 50, 8);
  89. ledcSetup(1, 50, 8);
  90. ledcSetup(2, 50, 8);
  91. ledcSetup(3, 50, 8);
  92. ledcSetup(4, 50, 8);
  93. ledcAttachPin(LEDRED, 0);
  94. ledcAttachPin(LEDGREEN, 1);
  95. ledcAttachPin(LEDBLUE, 2);
  96. ledcAttachPin(LedPin, 3);
  97. ledcAttachPin(Sound, 4);
  98. }
  99.  
  100. void loop() {
  101. Blynk.run();
  102.  
  103. myservo.write(butt);
  104. // клава
  105. boardstate = analogRead(BOARDPIN) / 205;
  106. if (boardstate != 9) {
  107. LEDWRITE();
  108. Serial.println(boardstate);
  109. }
  110. // освещение
  111. Light();
  112.  
  113. // сигнализация
  114. if()
  115. SIGNALIZACIA();
  116.  
  117. }
  118. //серво
  119. BLYNK_WRITE(V0) {
  120. butt = param.asInt();
  121. if(butt==1){
  122. butt=90;
  123. }else{
  124. butt=0;
  125. };
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement