Advertisement
Guest User

Untitled

a guest
Jan 1st, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.24 KB | None | 0 0
  1. #include <LedControl.h>
  2. #include <Keypad.h>
  3.  
  4. // Display a digit on a 7-segent display
  5. LedControl mydisplay = LedControl(13, 12, 11, 1);
  6.  
  7. // Digital Keypad 4x3
  8. const byte rows = 4; //four rows
  9. const byte cols = 3; //three columns
  10. char keys[rows][cols] = {
  11.   {'1','2','3'},
  12.   {'4','5','6'},
  13.   {'7','8','9'},
  14.   {'#','0','*'}
  15. };
  16. // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
  17. byte rowPins[rows] = {1, 6, 5, 3};
  18. // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
  19. byte colPins[cols] = {2, 0, 4};
  20. Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
  21.  
  22. char PROGRAM; // What type of program
  23. int i = 0;
  24. void setup()
  25. {
  26.    
  27.    mydisplay.shutdown(0, false);  // turns on display
  28.    mydisplay.setIntensity(0, 15); // 15 = brightest
  29.    
  30.    pinMode(13, OUTPUT); // Green LED
  31.    digitalWrite(13, 0); // Green LED low
  32.    
  33.    PROGRAM = kpd.waitForKey(); // waint until pressed key
  34.    LED(); // blink
  35. }
  36.  
  37. void loop()
  38. {
  39.   if (PROGRAM == '1')
  40.   {
  41.     // MÄSKPROCESS
  42.   }
  43.   else if (PROGRAM == '2')
  44.   {
  45.     // KOKPROCESS
  46.   }
  47.   else if (PROGRAM == '3')
  48.   {
  49.     // KYLPROCESS
  50.   }
  51.   else
  52.   {
  53.     show_digit(0); // show zero only 0000
  54.     PROGRAM = kpd.waitForKey(); // Waint until a key are pressed
  55.     LED(); // blink
  56.   }
  57.  
  58. }
  59.  
  60. void setTimeHumle()
  61. {
  62.  
  63. }
  64.  
  65. void speaker()
  66. {
  67.  
  68. }
  69.  
  70. void setEndTimeKok()
  71. {
  72.  
  73. }
  74.  
  75. void setTempKok()
  76. {
  77.  
  78. }
  79.  
  80. void setBeginTimeLak()
  81. {
  82.  
  83. }
  84.  
  85. void setTempLak()
  86. {
  87.  
  88. }
  89.  
  90. void relay_kok()
  91. {
  92.  
  93. }
  94.  
  95. void relay_lak()
  96. {
  97.  
  98. }
  99.  
  100. void getTempKok()
  101. {
  102.  
  103. }
  104.  
  105. void getTempLak()
  106. {
  107.  
  108. }
  109.  
  110. int tempsensor_kok()
  111. {
  112.   // get average temperature
  113. }
  114.  
  115. int tempsensor_lak()
  116. {
  117.   // get average temperature
  118. }
  119.  
  120. int digitalKeyPad()
  121. {
  122.  
  123. }
  124.  
  125. void show_digit(int i)
  126. {
  127.   // if i is 4 digit
  128.   if (i >= 1000)
  129.   {
  130.     String str = String(i);
  131.     int a = str[0] - '0';
  132.     int b = str[1] - '0';
  133.     int c = str[2] - '0';
  134.     int d = str[3] - '0';
  135.     mydisplay.setDigit(0, 0, a, false);
  136.     mydisplay.setDigit(0, 1, b, true);
  137.     mydisplay.setDigit(0, 2, c, false);
  138.     mydisplay.setDigit(0, 3, d, false);
  139.   }
  140.   // if i is 3 digit
  141.   else if (i <= 999 && i >= 100)
  142.   {
  143.     String str = String(i);
  144.     int a = str[0] - '0';
  145.     int b = str[1] - '0';
  146.     int c = str[2] - '0';
  147.     mydisplay.setDigit(0, 0, 0, false);
  148.     mydisplay.setDigit(0, 1, a, true);
  149.     mydisplay.setDigit(0, 2, b, false);
  150.     mydisplay.setDigit(0, 3, c, false);
  151.   }
  152.   // if i is 2 digit
  153.   else if(i < 100 && i >= 10)
  154.   {
  155.     String str = String(i);
  156.     int a = str[0] - '0';
  157.     int b = str[1] - '0';
  158.     mydisplay.setDigit(0, 0, 0, false);
  159.     mydisplay.setDigit(0, 1, 0, false);
  160.     mydisplay.setDigit(0, 2, a, false);
  161.     mydisplay.setDigit(0, 3, b, false);
  162.   }
  163.   else // if i is 1 digit
  164.   {
  165.     String str = String(i);
  166.     int a = str[0] - '0';
  167.     mydisplay.setDigit(0, 0, 0, false);
  168.     mydisplay.setDigit(0, 1, 0, false);
  169.     mydisplay.setDigit(0, 2, 0, false);
  170.     mydisplay.setDigit(0, 3, a, false);
  171.   }
  172. }
  173.  
  174. // Blink the LED if any button is pressed.
  175. void LED()
  176. {
  177.   int A = 1;
  178.   for (int i = 0; i <= 10; i++)
  179.   {
  180.     digitalWrite(13, A);
  181.     delay(100);
  182.     if (A == 1)
  183.     {
  184.       A = 0;
  185.     }
  186.     else
  187.     {
  188.       A = 1;
  189.     }
  190.   }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement