Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- int x = 7;
- int y = 0;
- byte ocitaj_taster()
- {
- int tmp = analogRead(0); //stanje tastera se ocitava preko
- //analognog ulaza 0
- if (tmp > 850 && tmp < 650) //SELECT
- return 1;
- if (tmp > 450 && tmp < 650) //LEFT
- return 2;
- if (tmp > 50 && tmp <250) //UP
- return 3;
- if (tmp > 250 && tmp < 450) //DOWN
- return 4;
- if (tmp < 50) //RIGHT
- return 5;
- return 0; //nije pritisnut nijedan od tastera
- }
- void setup() {
- lcd.begin(16,2);
- }
- void loop() {
- int key = ocitaj_taster();
- delay(100);
- switch(key){
- case 2:
- if( x > 0 && x <= 13) {
- x--;
- }
- break;
- case 3:
- if( y == 1) {
- y--;
- }
- break;
- case 4:
- if( y == 0) {
- y++;
- }
- break;
- case 5:
- if( x >= 0 && x < 13) {
- x++;
- }
- break;
- }
- lcd.clear();
- lcd.setCursor(x,y);
- lcd.print("^_^");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement