Guest User

Untitled

a guest
Aug 31st, 2012
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.94 KB | None | 0 0
  1. #include "DHT.h"
  2. #define DHTPIN A5
  3. #define DHTTYPE DHT11
  4. DHT dht(DHTPIN, DHTTYPE);
  5.  
  6. #define PIN_SCE 12
  7. #define PIN_RESET 13
  8. #define PIN_DC 11
  9. #define PIN_SDIN 1
  10. #define PIN_SCLK 0
  11.  
  12. // COnfiguration for the LCD
  13. #define LCD_C LOW
  14. #define LCD_D HIGH
  15. #define LCD_CMD 0
  16.  
  17. // Size of the LCD
  18. #define LCD_X 84
  19. #define LCD_Y 48
  20.  
  21. int scrollPosition = -10;
  22.  
  23. static const byte ASCII[][5] =
  24. {
  25. {0x00, 0x00, 0x00, 0x00, 0x00} // 20
  26. ,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
  27. ,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
  28. ,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
  29. ,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
  30. ,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
  31. ,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
  32. ,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
  33. ,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
  34. ,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
  35. ,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
  36. ,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
  37. ,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
  38. ,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
  39. ,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
  40. ,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
  41. ,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
  42. ,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
  43. ,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
  44. ,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
  45. ,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
  46. ,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
  47. ,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
  48. ,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
  49. ,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
  50. ,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
  51. ,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
  52. ,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
  53. ,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
  54. ,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
  55. ,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
  56. ,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
  57. ,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
  58. ,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
  59. ,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
  60. ,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
  61. ,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
  62. ,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
  63. ,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
  64. ,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
  65. ,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
  66. ,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
  67. ,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
  68. ,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
  69. ,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
  70. ,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
  71. ,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
  72. ,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
  73. ,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
  74. ,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
  75. ,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
  76. ,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
  77. ,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
  78. ,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
  79. ,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
  80. ,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
  81. ,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
  82. ,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
  83. ,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
  84. ,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
  85. ,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥
  86. ,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
  87. ,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
  88. ,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
  89. ,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
  90. ,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
  91. ,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
  92. ,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
  93. ,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
  94. ,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
  95. ,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
  96. ,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
  97. ,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
  98. ,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
  99. ,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
  100. ,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
  101. ,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
  102. ,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
  103. ,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
  104. ,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
  105. ,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
  106. ,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
  107. ,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
  108. ,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
  109. ,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
  110. ,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
  111. ,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
  112. ,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
  113. ,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
  114. ,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
  115. ,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
  116. ,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
  117. ,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
  118. ,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
  119. ,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
  120. ,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f →
  121. };
  122.  
  123. void LcdCharacter(char character)
  124. {
  125. LcdWrite(LCD_D, 0x00);
  126. for (int index = 0; index < 5; index++)
  127. {
  128. LcdWrite(LCD_D, ASCII[character - 0x20][index]);
  129. }
  130. LcdWrite(LCD_D, 0x00);
  131. }
  132.  
  133. void LcdClear(void)
  134. {
  135. for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
  136. {
  137. LcdWrite(LCD_D, 0x00);
  138. }
  139. }
  140.  
  141. void LcdInitialise(void)
  142. {
  143. pinMode(PIN_SCE, OUTPUT);
  144. pinMode(PIN_RESET, OUTPUT);
  145. pinMode(PIN_DC, OUTPUT);
  146. pinMode(PIN_SDIN, OUTPUT);
  147. pinMode(PIN_SCLK, OUTPUT);
  148.  
  149. digitalWrite(PIN_RESET, LOW);
  150. digitalWrite(PIN_RESET, HIGH);
  151.  
  152. LcdWrite(LCD_CMD, 0x21); // LCD Extended Commands.
  153. LcdWrite(LCD_CMD, 0xBf); // Set LCD Vop (Contrast). //B1
  154. LcdWrite(LCD_CMD, 0x04); // Set Temp coefficent. //0x04
  155. LcdWrite(LCD_CMD, 0x14); // LCD bias mode 1:48. //0x13
  156. LcdWrite(LCD_CMD, 0x0C); // LCD in normal mode. 0x0d for inverse
  157. LcdWrite(LCD_C, 0x20);
  158. LcdWrite(LCD_C, 0x0C);
  159. }
  160.  
  161. void LcdString(char *characters)
  162. {
  163. while (*characters)
  164. {
  165. LcdCharacter(*characters++);
  166. }
  167. }
  168.  
  169. void LcdWrite(byte dc, byte data)
  170. {
  171. digitalWrite(PIN_DC, dc);
  172. digitalWrite(PIN_SCE, LOW);
  173. shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
  174. digitalWrite(PIN_SCE, HIGH);
  175. }
  176.  
  177. /**
  178. * gotoXY routine to position cursor
  179. * x - range: 0 to 84
  180. * y - range: 0 to 5
  181. */
  182. void gotoXY(int x, int y)
  183. {
  184. LcdWrite( 0, 0x80 | x); // Column.
  185. LcdWrite( 0, 0x40 | y); // Row.
  186. }
  187.  
  188. void drawBox(void)
  189. {
  190. int j;
  191. for(j = 0; j < 84; j++) // top
  192. {
  193. gotoXY(j, 0);
  194. LcdWrite(1, 0x01);
  195. }
  196.  
  197. for(j = 0; j < 84; j++) //Bottom
  198. {
  199. gotoXY(j, 5);
  200. LcdWrite(1, 0x80);
  201. }
  202.  
  203. for(j = 0; j < 6; j++) // Right
  204. {
  205. gotoXY(83, j);
  206. LcdWrite(1, 0xff);
  207. }
  208.  
  209. for(j = 0; j < 6; j++) // Left
  210. {
  211. gotoXY(0, j);
  212. LcdWrite(1, 0xff);
  213. }
  214. }
  215.  
  216. void Scroll(String message)
  217. {
  218. for (int i = scrollPosition; i < scrollPosition + 11; i++)
  219. {
  220. if ((i >= message.length()) || (i < 0))
  221. {
  222. LcdCharacter(' ');
  223. }
  224. else
  225. {
  226. LcdCharacter(message.charAt(i));
  227. }
  228. }
  229. scrollPosition++;
  230. if ((scrollPosition >= message.length()) && (scrollPosition > 0))
  231. {
  232. scrollPosition = -10;
  233. }
  234. }
  235.  
  236. void setup(void)
  237. {
  238. dht.begin();
  239. LcdInitialise();
  240. LcdClear();
  241. drawBox();
  242. gotoXY(5,1);
  243. LcdString("SECRETX");
  244. }
  245.  
  246. void loop(void)
  247. {
  248. float para = dht.readHumidity();
  249. float homerseklet = dht.readTemperature();
  250. char buf [10];
  251. gotoXY(5,3);
  252. LcdString(itoa (homerseklet, buf, 10));
  253. gotoXY(20,3);
  254. LcdString("fok");
  255. gotoXY(5,2);
  256. LcdString(itoa (para, buf, 10));
  257. gotoXY(20,2);
  258. LcdString("rH");
  259. delay(5000);
  260. gotoXY(5,4);
  261. Scroll("←");
  262. }
Advertisement
Add Comment
Please, Sign In to add comment