Advertisement
lukicdarkoo

Pattern for Arduino LCD Keypad Shield

Dec 10th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. // Pattern for Arduino LCD Keypad Shield
  2. // Create custom character: https://omerk.github.io/lcdchargen/
  3. // String reference: https://www.arduino.cc/en/Reference/StringObject
  4. // LCD reference: https://www.arduino.cc/en/Reference/LiquidCrystal
  5. // Stream reference: http://playground.arduino.cc/Main/StreamingOutput
  6.  
  7. #include <LiquidCrystal.h>
  8. #define TIMEOUT 10
  9.  
  10. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  11.  
  12. void setup() {
  13.   // Initialize Serial
  14.   Serial.begin(9600);
  15.   Serial.setTimeout(TIMEOUT);
  16.  
  17.   // Initialize LCD and special characters
  18.   lcd.begin(16, 2);
  19.  
  20.   // Generate completely random
  21.   randomSeed(analogRead(1));
  22. }
  23.  
  24. void loop() {
  25.   if (Serial.available() > 0) {
  26.      
  27.   }
  28. }
  29.  
  30. char readKey() {
  31.   short tolerance = 5;
  32.   short value = analogRead(0);
  33.   short values[] = {639, 408, 255, 99, 0};
  34.   char out[]  = {'s', 'l', 'd', 'u', 'r'};
  35.   for (int i = 0; i < 5; i++) {
  36.     if (values[i] - tolerance < value && values[i] + tolerance > value) {
  37.       return out[i];
  38.     }
  39.   }
  40.  
  41.   return '-';
  42. }
  43.  
  44. String getRandomString(int n) {
  45.     // Awful optimisation, but easy to scale
  46.     char charset[] = "0123456789"
  47.                      "abcdefghijklmnopqrstuvwxyz"
  48.                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  49.     String randomString = "";
  50.     for (int i = 0; i < n; i++) {
  51.       randomString += String(charset[random(0, strlen(charset))]);
  52.     }
  53.     return randomString;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement