Go Down

Topic: interrupts and tft (Read 4983 times) previous topic - next topic

leds_are_cool

  • Check the state of the flag in the main loop, say after a image has been drawn and then clear the flag and clear the screen. In this case the button press action will wait to the end of the image drawing.

ok now i found out that my interrupt is working and i already had in mind on doing what you say in option 1.
but yea it waits for drawing bitmap to be done.

option 2 isnt a option for me so what is another way to do it becouse interrupt are not going to work?

rowboteer

Option 2 is the most practical approach if you wish to continue to use the Adafruit library.

Option 1 is hampered because Adafruit graphics library is very slow at plotting to the screen. You could try one of the compatible enhanced libraries available, for example this one.

This is another one that looks to be very good and should be compatible. It runs very fast but it cuts the timing of the SPI transactions down to a absolute minimum and some folk have trouble with plotting errors.

You should be able to get the full screen image plotting off an SDCard down to much less than one second with these libraries and screen clearing in around 0.2 seconds!

This then makes option 1 much more palatable.

rowboteer

#32
Jul 31, 2015, 01:10 pm Last Edit: Jul 31, 2015, 01:11 pm by rowboteer
Hi, had a look at the spitftbitmap example sketch in the Adafruit library, I assume you have based your code on that and the bmpDraw() function contained in it. If that is the case then find these lines in the function bmpDraw():

          } // end pixel
        } // end scanline

Change to:

          } // end pixel
        if (button_pressed==1) row = h;
        } // end scanline

This assumes that the interrupt routine has set a variable, i.e. button_pressed=1.

The button press will then stop the drawing of the image at the end of a scan line and return to the main loop. Where you can then perform the operations described in Option 1.

Report back if this does/does not work.

leds_are_cool

yes it works.
i already tried that earlier.

but i wanna add other functions such as delay.

how to do that then?

rowboteer

#34
Aug 02, 2015, 12:27 am Last Edit: Aug 02, 2015, 07:30 pm by rowboteer
yes it works
Great, so option 2 works. Now we can move on to your new problem.

but i wanna add other functions such as delay.

The simplest way is to use the built in function:

delay (value);

Where the value is the delay you want in milliseconds, eg 1000 will give a delay of 1 second.

If you want an interruptible delay that exits on a button press,  then you will need to write a function.

pratto

I have read this thread 4 or 5 times and my takeaway is, if you want notice to be taken that a button has been pushed, while the program is busy doing something else, you can do it by using an interrupt that sets a flag that says "i've been pushed". When the program gets freed up, it looks for flags, and then will execute an ISR. is that about right ?

I think my situation is similar. My buttons are inside the void loop, and i have to press the button at Exactly the right time as the focus of the sketch flies by, in order to get the button to take. it continuously loops around gathering sensor input. and i can't figure out a way to make it pause for a few seconds so i can leisurely press the button.

i have tried using a millis() timer, but couldn't get it to work.

the idea of learning about interrupts and flags, and interrupt button routine and volatile, etc. is pretty daunting. i'm wondering if there is a simpler way, and if not can you point me at some good EXAMPLES of how to use interrupts, flags, etc. ?

from rowboteer :
Quote
As a starter to check if the interrupt button routine is working OK just switch on a LED in the interrupt handler and switch it off in the main loop.  This will show that the button press has been recorded and that it has been actioned in the main loop.

There are a few "gotchas" when using interrupts, for example the flag to be set in the interrupt routine should be declared as "volatile". This is because the compiler may create code that sometimes creates a temporary "copy" of the variable rather than the "master" variable. The other "gotcha" is switch bounce, where the switch contacts bounce calling the interrupt routines multiple times and even at a time when the button is released...
I don't have any swithes, just screen buttons.

Paul__B

I don't have any switches, just screen buttons.
Which are software, so interrupts are not going to help you.

pratto

hhmmm... i missed that part. i guess his referring to a button fit so well into what i was looking for that, with the subject being tft, i assumed he meant an on-screen button.

back to millis timer for me.

Go Up