Advertisement
Narayan

arduino

Feb 21st, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.38 KB | None | 0 0
  1. #include <LiquidCrystal.h> //Include LCDs Library
  2. #include <string.h>
  3.  
  4. LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Attach LCDs and Arduino pin comunnication
  5.  
  6. short int time; //Entire variable declaration(time)
  7. short int col = 20, row = 4, i, j;
  8.  
  9. byte customChar0[8] = {
  10.                       0b11111,
  11.                       0b11110,
  12.                       0b11110,
  13.                       0b11100,
  14.                       0b11100,
  15.                       0b11000,
  16.                       0b11000,
  17.                       0b10000
  18. };
  19.  
  20. byte customChar1[8] = {
  21.                      0b11111,
  22.                      0b00000,
  23.                      0b00000,
  24.                      0b11011,
  25.                      0b11011,
  26.                      0b00000,
  27.                      0b00000,
  28.                      0b01110
  29. };
  30.  
  31. byte customChar2[8] = {
  32.                       0b11111,
  33.                       0b01111,
  34.                       0b01111,
  35.                       0b00111,
  36.                       0b00111,
  37.                       0b00011,
  38.                       0b00011,
  39.                       0b00001
  40. };
  41.  
  42. byte customChar3[8] = {
  43.                       0b10000,
  44.                       0b11000,
  45.                       0b11000,
  46.                       0b11100,
  47.                       0b11100,
  48.                       0b11110,
  49.                       0b11110,
  50.                       0b11111
  51. };
  52.  
  53. byte customChar4[8] = {
  54.                       0b00100,
  55.                       0b00000,
  56.                       0b00000,
  57.                       0b10001,
  58.                       0b01010,
  59.                       0b00100,
  60.                       0b00000,
  61.                       0b11111
  62. };
  63.  
  64. byte customChar5[8] = {
  65.                       0b00001,
  66.                       0b00001,
  67.                       0b00011,
  68.                       0b00011,
  69.                       0b00111,
  70.                       0b00111,
  71.                       0b01111,
  72.                       0b11111
  73. };
  74.  
  75. char message [512];
  76.  
  77. short int set_start_point (char *messg) {
  78.   short int val1 = 0, val2 = 0, mssg_len = 0;
  79.  
  80.   mssg_len = strlen (messg);
  81.   val1 = col - mssg_len;
  82.   return val2 = val1 / 2;  
  83. }
  84.  
  85. void setup(){
  86.   lcd.createChar(0, customChar0);
  87.   lcd.createChar(1, customChar1);
  88.   lcd.createChar(2, customChar2);
  89.   lcd.createChar(3, customChar3);
  90.   lcd.createChar(4, customChar4);
  91.   lcd.createChar(5, customChar5);
  92.   lcd.begin(20, 4);
  93.   for (i = 0; i <= 2; i++){
  94.       lcd.setCursor (8 + i, 2);
  95.       lcd.write (byte (i));
  96.     }
  97.    for (j = 3; j <= 5; j++){
  98.      lcd.setCursor (5 + j, 3);
  99.      lcd.write (byte (j));
  100.    }
  101. }
  102.  
  103. void loop(){
  104.   strcpy (message, "Hello Smile!");
  105.   lcd.setCursor(set_start_point (message), 0); // Set cursor to correct position
  106.   lcd.print (message);
  107.   strcpy (message, "Elapsed Time:");
  108.   lcd.setCursor(set_start_point (message), 1); // Set cursor to correct position
  109.   lcd.print (message);
  110.   lcd.setCursor(set_start_point (message) + strlen (message), 1); // Set cursor to correct position
  111.   lcd.print(time); // Write the current value of the count variable in the LCD
  112.  
  113.   delay(1000); // Waits for 1 second
  114.  
  115.   time++; // Increment count variable
  116.  
  117.   if(time == 10){
  118.     time = 0; //... resets the count variable
  119.     lcd.clear ();
  120.     for (i = 0; i <= 2; i++){
  121.       lcd.setCursor (8 + i, 2);
  122.       lcd.write (byte (i));
  123.     }
  124.    for (j = 3; j <= 5; j++){
  125.      lcd.setCursor (5 + j, 3);
  126.      lcd.write (byte (j));
  127.    }
  128.   }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement