Advertisement
Guest User

Untitled

a guest
Oct 5th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #define BTN_LED 6
  2. int req;
  3. int bblink;
  4. int bled;
  5. unsigned long timer;
  6. int tb;
  7. bool block;
  8. bool re;
  9.  
  10.  
  11. void ledbtn_mode(int sd) {
  12. switch (sd) {
  13. case 1:
  14. if(bblink != 1) {
  15. digitalWrite(BTN_LED, HIGH);
  16. bblink = 1;
  17. }
  18. break;
  19. case 5:
  20. if(bblink != 5) {
  21. block = false;
  22. tb = 0;
  23. timer = millis();
  24. bblink = 5;
  25. }
  26. break;
  27.  
  28. }
  29. }
  30.  
  31. void setup() {
  32. Serial.begin(115200);
  33. pinMode(BTN_LED, OUTPUT);
  34. }
  35.  
  36. void loop() {
  37. if(Serial.available() > 0) {
  38. req = Serial.parseInt();
  39. }
  40. if(req == 10){
  41. ledbtn_mode(1);
  42. } else if(req == 15) {
  43. ledbtn_mode(5);
  44. }
  45.  
  46. if(bblink == 5) {
  47. if(tb < 6 && (millis() - timer) >= 500) {
  48. if(digitalRead(BTN_LED) == HIGH) {
  49. bled = LOW;
  50. } else {
  51. bled = HIGH;
  52. }
  53. digitalWrite(BTN_LED, bled);
  54. tb++;
  55. timer = millis();
  56. } else if(tb >= 6 && block == false) {
  57. Serial.println("<320>");
  58. if(digitalRead(BTN_LED) == LOW) {
  59. digitalWrite(BTN_LED, HIGH);
  60. }
  61. block = true;
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement