Pages: [1]   Go Down
Author Topic: TFT display multiple images  (Read 402 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I have Arduino Micro and Arduino TFT display. I want to display one of 8 bmp images on the screen by the simple 8 buttons.

I write the code like this:

#include <SPI.h>
#include <SD.h>
#include <TFT.h>

#define sd_cs  8
#define lcd_cs 7
#define dc     0
#define rst    1 

TFT screen = TFT(lcd_cs, dc, rst);

  PImage one, two, three, four, five, six, seven, eight;

void setup() {

  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  pinMode(11, INPUT);
 
  screen.begin();
  SD.begin(sd_cs);
  screen.background(255, 255, 255);

  one = screen.loadImage("one.bmp");
  two = screen.loadImage("two.bmp");
  three = screen.loadImage("three.bmp");
  four = screen.loadImage("four.bmp");
  five = screen.loadImage("five.bmp");
  six = screen.loadImage("six.bmp");
  seven = screen.loadImage("seven.bmp");
  eight = screen.loadImage("eight.bmp");
 
}

void loop() {
    if (digitalRead(2) == HIGH){
      screen.image(one, 0, 0);
    while (digitalRead(2) == HIGH){};
}
    if (digitalRead(3) == HIGH){
      screen.image(two, 0, 0);
    while (digitalRead(3) == HIGH){};
}
    if (digitalRead(4) == HIGH){
      screen.image(three, 0, 0);
    while (digitalRead(4) == HIGH){};
}
    if (digitalRead(5) == HIGH){
      screen.image(four, 0, 0);
    while (digitalRead(5) == HIGH){};
}
    if (digitalRead(6) == HIGH){
      screen.image(five, 0, 0);
    while (digitalRead(6) == HIGH){};
}
    if (digitalRead(9) == HIGH){
      screen.image(six, 0, 0);
    while (digitalRead(9) == HIGH){};
}
    if (digitalRead(10) == HIGH){
      screen.image(seven, 0, 0);
    while (digitalRead(10) == HIGH){};
}
    if (digitalRead(11) == HIGH){
      screen.image(eight, 0, 0);
    while (digitalRead(11) == HIGH){};
}

}


First two or three photos works fine, but other do not display, on the screen appears only lines.
Maybe it's some memory leak or smth,

Can you help me solve this problem?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23782
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You do not say how the buttons are connected.
I would do this:
change these like so:
pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);

and the read lines to match:
    if (digitalRead(2) == LOW){
      screen.image(one, 0, 0);
    while (digitalRead(2) == LOW){};
}

And wire the buttons to connect the pins to Gnd. The internal pullup resistors will hold the pins High when the buttons are not pressed.

If that doesn't solve it, try changing this line:

screen.image(one, 0, 0);

to call out the files that are not working (two thru eight), and confirm all the files can display.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Sr. Member
****
Karma: 12
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My guess is you ran out of memory.

Try only loading them when you're about to display them, then freeing the memory afterwards.

Also, you could add the image checks after the loads:

  if (image.isValid() != true) {
    Serial.println("error while loading arduino.bmp");
  }
« Last Edit: October 16, 2013, 01:16:55 pm by arduinodlb » Logged

Do not IM me. I will not respond. Ask questions in the forum.

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10445
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Attempting to cache images on a microcontroller with 2k of RAM is just going to
overflow memory, just load the image when needed and use only one PImage variable??
How large are these images?
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: