Hello there, i'm making a simple menu with TVout and IRremote.
Well, when i try a example of IRremote library it works fine.
but when i try this :
#include <IRremote.h>
#include <TVout.h>
#include <font6x8.h>
//IR
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
//TV
TVout TV;
#define SCREEN_WIDTH 120
#define SCREEN_HEIGHT 80
//MENU
int CursorX = 0;
int CursorY = 0;
String text = "";
//TIMER
#define FREQUENCY 30
long timer = 0;
char textTable[3][10] = { //3 lines
{ 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P' },//10 letters
{ 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ' ' },//10 letters
{ ' ', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '_', ' ' } //10 letters
};
void setup() {
//WELCOME SCREEN
Serial.begin(9600);
Serial.println("TV infrared controller");
Serial.print("Initializing IR controller");
for(int i = 0; i < 3; i ++) { delay(250); Serial.print("."); }
Serial.println("done");
Serial.flush();
//IR RECEIVER
irrecv.enableIRIn();
pinMode(13, OUTPUT);
Serial.print("Initializing TV controller");
for(int i = 0; i < 3; i ++) { delay(250); Serial.print("."); }
Serial.println("done");
Serial.flush();
//TV
TV.begin(PAL, SCREEN_WIDTH, SCREEN_HEIGHT);
TV.select_font(font6x8);
timer = millis();
}
void loop() {
updateButtons();
if(millis() - timer >= FREQUENCY) {
updateTV();
timer = millis();
}
}
void updateTV () {
TV.clear_screen();
//DRAW TABLE
//LINES
//for(int i = 0; i < SCREEN_HEIGHT / 8; i++){ TV.draw_line(i * 8, 0, i * 8, 26, 1); }//VERTICAL
//for(int i = 0; i < SCREEN_WIDTH / 6; i++){ TV.draw_line(0, i * 6, 20, i * 6, 1); }//HORIZONTAL
//CHARACTERS TABLE
for(int column = 0; column < 10; column++) { TV.print_char(column * 6 + 1, 1, textTable[0][column]); }//FIRST LINE
for(int column = 0; column < 10; column++) { TV.print_char(column * 6 + 4, 9, textTable[1][column]); }//SECOND LINE
for(int column = 0; column < 10; column++) { TV.print_char(column * 6 + 1, 17, textTable[2][column]); }//THIRD LINE
//CURSOR RECTANGLE
if(CursorY == 0) { TV.draw_rect(CursorX*6, 8, (CursorX + 1)*6, 8, 2, 2); }
else if(CursorY == 1) { TV.draw_rect(CursorX*6+3, 16, (CursorX + 1)*6, 16, 2, 2); }
else if(CursorY == 2) { TV.draw_rect(CursorX*6+1, 24, (CursorX + 1)*6, 24, 2, 2); }
//BUFFER STRING
TV.print(SCREEN_WIDTH-6, SCREEN_HEIGHT-8, text.c_str());
}
void updateButtons () {
if (irrecv.decode(&results)) {
irrecv.resume();
}
if(results.value != 0) {
Serial.print("Infrared signal received : 0x");
Serial.println(results.value, HEX);
decodeButton();
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
}
void decodeButton () {
switch (results.value) {
case 0x8070A658://UP
CursorY--;
break;
case 0x80702659://DOWN
CursorY++;
break;
case 0x8070265B://RIGHT
CursorX++;
break;
case 0x8070A65A://LEFT
CursorX--;
break;
case 0x8070265C://ENTER
text += textTable[CursorX][CursorY];
break;
}
if(CursorY < 0) CursorY = 3;
else if(CursorY > 3) CursorY = 0;
if(CursorX < 0) CursorX = 10;
else if(CursorX > 10) CursorX = 0;
}
doesn't works.
Can someone tell me what is wrong ?
Thanks.