Advertisement
RealHero

Arduino 6

Jun 5th, 2021
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #define FIRST_SEGMENT_PIN 0
  2.  
  3. #define SECOND_SEGMENT_PIN 7
  4.  
  5. #define SEGMENT_COUNT 7
  6.  
  7. byte numberSegments[10] = {
  8.  
  9. 0b00111111, 0b00001010, 0b01011101, 0b01011110, 0b01101010,
  10.  
  11. 0b01110110, 0b01110111, 0b00011010, 0b01111111, 0b01111110,
  12.  
  13. };
  14.  
  15. void setup()
  16.  
  17. {
  18.  
  19. for (int i = 0; i < 2 * SEGMENT_COUNT; i++)
  20.  
  21. pinMode(i, OUTPUT);
  22.  
  23. }
  24.  
  25. int firstNum;
  26.  
  27. int secondNum;
  28.  
  29. void loop(){
  30.  
  31. for(int time = 99; time >= 0; time--)
  32.  
  33. {
  34.  
  35. delay(1000);
  36.  
  37. firstNum = time % 10;
  38.  
  39. secondNum = time / 10;
  40.  
  41. Print(firstNum, FIRST_SEGMENT_PIN);
  42.  
  43. Print(secondNum, SECOND_SEGMENT_PIN);
  44.  
  45. }
  46.  
  47. }
  48.  
  49. // Функция вывода значений на экран.
  50.  
  51. void Print(int num, int startPin)
  52.  
  53. {
  54.  
  55. int mask = numberSegments[num];
  56.  
  57. for (int i = 0; i < SEGMENT_COUNT; ++i)
  58.  
  59. {
  60.  
  61. boolean enableSegment = bitRead(mask, i);
  62.  
  63. digitalWrite(i + startPin, enableSegment);
  64.  
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement