Mandalorian Mercs Costume Club

Mandalorian Armor => Equipment & Accessories => Electronics => Topic started by: Bar'uun Strieg on Apr 04, 2017, 12:16 PM

Title: Help needed for Gauntlet Display controlled by Arduino
Post by: Bar'uun Strieg on Apr 04, 2017, 12:16 PM
First..........Writing code is NOT my strong suit and I need some help.

Project is to have a small 1.8" TFT display controlled by an Arduino mounted on my left gauntlet.  I found some Arduino Code that will cycle through images on the display (think electronic photo frame), but I really want to add a button that will cycle to the next image when pressed, and ultimately have a second button as a "back to previous image" function.

I started with the project from this link:
https://learn.adafruit.com/1-8-tft-display/overview?view=all (https://learn.adafruit.com/1-8-tft-display/overview?view=all)

I found this example which basically turns it into a digital photo frame.
http://blog.simtronyx.de/en/an-image-slideshow-with-an-arduino-and-a-tft-display-with-a-sd-card-module/ (http://blog.simtronyx.de/en/an-image-slideshow-with-an-arduino-and-a-tft-display-with-a-sd-card-module/)

If anybody know Arduino code and can help modify the sketch to use buttons as forward and back functions for the display, it would be greatly appreciated.
Title: Re: Help needed for Gauntlet Display controlled by Arduino
Post by: Kuu on Apr 04, 2017, 01:18 PM
You should be able to leverage my ammo counter.

http://mandalorianmercs.org/forum/index.php?topic=91886.msg1348087#msg1348087

Title: Re: Help needed for Gauntlet Display controlled by Arduino
Post by: Bar'uun Strieg on Apr 04, 2017, 01:34 PM
You should be able to leverage my ammo counter.

http://mandalorianmercs.org/forum/index.php?topic=91886.msg1348087#msg1348087

Thanks Kuu, but I really don't know the code well enough to figure my problem out.....I've been slamming my head against a wall trying to get it to work, but haven't had any luck.....just frustration.
Title: Re: Help needed for Gauntlet Display controlled by Arduino
Post by: Kuu on Apr 05, 2017, 12:19 PM
I'd need to get those parts to test the code but conceptually:

So in my code I setup 2 buttons
  buttonPin
  buttonReloadPin
and
  buttonState
  buttonReloadState

Then in the setup() I tell the code those buttons exist
  pinMode(buttonPin,INPUT);
  pinMode(buttonReloadPin,INPUT);

Then in the loop() I read the buttons   
  buttonState = digitalRead(buttonPin);   
  buttonReloadState = digitalRead(buttonReloadPin);

and if they're pressed (buttonReloadState==0 and buttonState==0) I do stuff.

Basically you want to take that example code and stick it inside a button press

  if (buttonState==0)
  {
   Do stuff to advance the picture
  }

  if (buttonReloadState==0)
  {
  Do stuff to go back a picture or restart the process
  }

And you'll want to take out the delay stuff since you want the buttons to control it.
Title: Re: Help needed for Gauntlet Display controlled by Arduino
Post by: Bar'uun Strieg on Apr 05, 2017, 12:46 PM
Thanks Kuu.  One problem I ran into last night was when I defined
const int buttonPin = 7;

then tried to use
pinMode(buttonPin, INPUT);

The code wouldn't compile and errored on the pinMode line.....I wish I knew code better.  This is frustrating the crap out of me.
Title: Re: Help needed for Gauntlet Display controlled by Arduino
Post by: LightningLion on Apr 22, 2017, 10:13 AM
In the ADAFruit code add this variables, pinModes in the setup and replace loop with this one. DON'T delete bmpDraw function.
If this doesn't work let me know which error you receive.

It would work as long as your images are named:
image_X.bmp (for 1 digit)
image_XY.bmp (for 2 digits).

It won't work if first iamges are called image_02.bmp for example.

Code: [Select]

int bmpcount = 1;
const int bmpmaxnumber = 99; //highest number of bitmaps on your SD.
String bmpname = "image_01.bmp";
const byte prevButton = 3;
const byte nextButton = 4;
int incomingByte = 0;   // for incoming serial data

void setup(){
   
    pinMode(prevButton, INPUT);
    pinMode(nextButton, INPUT);
    bmpDraw("image_1.bmp", 0, 0);

}

void loop(){ 
 
    if ((prevButton == LOW) && (nextButton == HIGH)) {
    //let's go one pic forward
      if (bmpcount < bmpmaxnumber){
        bmpcount++;
      } else {
        bmpcount = bmpmaxnumber;
      }
     
      bmpname = "image_" + String(bmpcount) + ".bmp";
      bmpDraw(bmpname, 0, 0);
     
   
   
    }
   
    if ((prevButton == HIGH) && (nextButton == LOW)) {
    //let's go one pic back
   
      if (bmpcount > 1){
        bmpcount--;
      } else {
        bmpcount = 1;
      }
     
      bmpname = "image_" + String(bmpcount) + ".bmp";
      bmpDraw(bmpname, 0, 0);
   
    }

}
Title: Re: Help needed for Gauntlet Display controlled by Arduino
Post by: Bar'uun Strieg on Apr 27, 2017, 03:02 PM
In the ADAFruit code add this variables, pinModes in the setup and replace loop with this one. DON'T delete bmpDraw function.
If this doesn't work let me know which error you receive.

It would work as long as your images are named:
image_X.bmp (for 1 digit)
image_XY.bmp (for 2 digits).

It won't work if first iamges are called image_02.bmp for example.

Code: [Select]

int bmpcount = 1;
const int bmpmaxnumber = 99; //highest number of bitmaps on your SD.
String bmpname = "image_01.bmp";
const byte prevButton = 3;
const byte nextButton = 4;
int incomingByte = 0;   // for incoming serial data

void setup(){
   
    pinMode(prevButton, INPUT);
    pinMode(nextButton, INPUT);
    bmpDraw("image_1.bmp", 0, 0);

}

void loop(){ 
 
    if ((prevButton == LOW) && (nextButton == HIGH)) {
    //let's go one pic forward
      if (bmpcount < bmpmaxnumber){
        bmpcount++;
      } else {
        bmpcount = bmpmaxnumber;
      }
     
      bmpname = "image_" + String(bmpcount) + ".bmp";
      bmpDraw(bmpname, 0, 0);
     
   
   
    }
   
    if ((prevButton == HIGH) && (nextButton == LOW)) {
    //let's go one pic back
   
      if (bmpcount > 1){
        bmpcount--;
      } else {
        bmpcount = 1;
      }
     
      bmpname = "image_" + String(bmpcount) + ".bmp";
      bmpDraw(bmpname, 0, 0);
   
    }

}

Thank you!  I'll give it a try as soon as I can.  I'm in the middle of painting everything and this may have to wait a bit.  I do appreciate the response and will let you know what my results are.