Advertisement
Maxa

ARDUINO /// LCD_Smiley

Dec 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  3.  
  4. int x = 7;
  5. int y = 0;  
  6.  
  7. byte ocitaj_taster()
  8. {
  9.  int tmp = analogRead(0); //stanje tastera se ocitava preko
  10.  //analognog ulaza 0
  11.  if (tmp > 850 && tmp < 650) //SELECT
  12.  return 1;
  13.  if (tmp > 450 && tmp < 650) //LEFT
  14.  return 2;
  15.  if (tmp > 50 && tmp <250) //UP
  16.  return 3;
  17.  if (tmp > 250 && tmp < 450) //DOWN
  18.  return 4;
  19.  if (tmp < 50) //RIGHT
  20.  return 5;
  21.  return 0; //nije pritisnut nijedan od tastera
  22. }
  23.  
  24.  
  25. void setup() {
  26.  
  27.   lcd.begin(16,2);
  28.  
  29. }
  30.  
  31. void loop() {
  32.   int key = ocitaj_taster();
  33. delay(100);
  34.  
  35.   switch(key){
  36.     case 2:
  37.       if( x > 0 && x <= 13) {
  38.           x--;
  39.         }
  40.     break;
  41.    
  42.     case 3:
  43.       if( y == 1) {
  44.           y--;
  45.         }
  46.     break;
  47.    
  48.     case 4:
  49.       if( y == 0) {
  50.           y++;
  51.         }
  52.     break;
  53.    
  54.     case 5:
  55.       if( x >= 0 && x < 13) {
  56.           x++;
  57.         }
  58.     break;
  59.   }
  60.     lcd.clear();
  61.     lcd.setCursor(x,y);
  62.     lcd.print("^_^");
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement