Advertisement
babyyoda_

Segment

Feb 10th, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <IRremote.h>
  2. #include<MsTimer2.h>
  3.  
  4. #define Ssymbol 4
  5. #define digit1 5
  6. #define digit2 6
  7. #define RECV_PIN 7
  8. #define RELAY 8
  9. #define buzzer 13
  10. #define clock A4
  11. #define data A5
  12.  
  13. IRrecv irrecv(RECV_PIN);
  14. decode_results results;
  15. unsigned long key_value = 0;
  16.  
  17. int count = 0;
  18.  
  19. byte zero  = B00010010;
  20. byte one   = B11011110;
  21. byte two   = B00010101;
  22. byte three = B10010100;
  23. byte four  = B11011000;
  24. byte five  = B10110000;
  25. byte six   = B00110000;
  26. byte seven = B11010110;
  27. byte eight = B00010000;
  28. byte nine  = B11010000;
  29. byte clrs  = B11111111;
  30. byte night  = B00000001;
  31. byte timer  = B11111110;
  32.  
  33. byte Digit[] = {B00010010, B11011110, B00010101, B10010100, B11011000, B10110000, B00110000, B11010110, B00010000, B11010000};
  34. byte symbol[] = {B00000001, B11111110};
  35. int i, j;
  36. int DELAY = 5;
  37. int unit, tens;
  38.  
  39.  
  40. void setup() {
  41.  
  42.   Serial.begin(9600);
  43.  
  44.   irrecv.enableIRIn();
  45.   irrecv.blink13(false);
  46.  
  47.   pinMode(clock, OUTPUT);
  48.   pinMode(data , OUTPUT);
  49.   pinMode(digit1, OUTPUT);
  50.   pinMode(digit2, OUTPUT);
  51.   pinMode(RELAY, OUTPUT);
  52.   pinMode(buzzer, OUTPUT);
  53.   MsTimer2::set(5, setDigit_);
  54.   MsTimer2::start();
  55. }
  56.  
  57. void loop() {
  58.   if (irrecv.decode(&results)) {
  59.  
  60.     if (results.value == 0XFFFFFFFF)
  61.       results.value = key_value;
  62.  
  63.     if (results.value == 0x8800347) {
  64.       Serial.println("Button 1");
  65.       beep();
  66.       unit = 8;
  67.       tens = 8;
  68.     }
  69.     if (results.value == 0x88C0051) {
  70.       Serial.println("Button 2");
  71.       beep();
  72.       unit = 0;
  73.       tens = 0;
  74.     }
  75.     if (results.value == 0x88C000C) {
  76.       Serial.println("Button 3");
  77.       beep();
  78.       digitalWrite(RELAY, HIGH);  
  79.       unit = 6;
  80.       tens = 6;
  81.     }
  82.     key_value = results.value;
  83.     irrecv.resume();
  84.   }
  85. }
  86.  
  87. int setDigit_() {
  88.  
  89.   //  int unit, tens;
  90.   //  unit = D % 10;
  91.   //  tens = D / 10;
  92.     Serial.println("SET DIGIT");
  93.   digitalWrite(digit2, LOW);
  94.   shiftOut(data, clock, LSBFIRST, Digit[tens]);
  95.   digitalWrite(digit1, HIGH);
  96.   delay(DELAY);
  97.   digitalWrite(digit1, LOW);
  98.   shiftOut(data, clock, LSBFIRST, Digit[unit]);
  99.   digitalWrite(digit2, HIGH);
  100.   delay(DELAY);
  101. }
  102.  
  103. int beep() {
  104.   digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  105.   delay(100);                       // wait for a second
  106.   digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  107.   delay(100);
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement