Advertisement
milanmetal

ARDUINO // LCD + Palindrome string array

Dec 6th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1.  
  2. #include <LiquidCrystal.h>
  3. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  4.  
  5. int x = 7; // max x = 14
  6. int y = 0;  // max y = 1
  7. //int captcha = 0;
  8.  
  9. String smileys[15] = {"A", "N","A","V","O","L","I","M","I","L","O","V","A","N","A"};
  10.  
  11. byte ocitaj_taster()
  12. {
  13.  int tmp = analogRead(0); //stanje tastera se ocitava preko
  14.  //analognog ulaza 0
  15.  if (tmp > 635 && tmp < 645) //SELECT
  16.  return 1;
  17.  if (tmp > 405 && tmp < 415) //LEFT
  18.  return 2;
  19.  if (tmp > 95 && tmp < 105) //UP
  20.  return 3;
  21.  if (tmp > 252 && tmp < 262) //DOWN
  22.  return 4;
  23.  if (tmp < 5) //RIGHT
  24.  return 5;
  25.  return 0; //nije pritisnut nijedan od tastera
  26. }
  27.  
  28. int rez = 0;
  29. void setup() {
  30.  
  31.   lcd.begin(16,2);
  32.   lcd.setCursor(x,y);
  33.   lcd.print("<3");
  34. }
  35.  
  36. void loop() {
  37.   int key = ocitaj_taster();
  38. delay(300);
  39.  
  40.  
  41.  
  42.   //if(captcha == 1) {
  43.     switch(key){
  44.       case 2:
  45.         if( x > 0 && x <= 14) {
  46.             x--;
  47.           }
  48.       break;
  49.      
  50.       case 3:
  51.         if( y == 1) {
  52.             y--;
  53.           }
  54.       break;
  55.      
  56.       case 4:
  57.         if( y == 0) {
  58.             y++;
  59.           }
  60.       break;
  61.      
  62.       case 5:
  63.         if( x >= 0 && x < 14) {
  64.             x++;
  65.           }
  66.       break;
  67.     }
  68.   //}
  69.     lcd.clear();
  70.     lcd.setCursor(x,y);
  71.     lcd.print(smileys[x]);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement