TinyCircuits Forum

TinyCircuits Products => TinyDuino Processors & TinyShields => Topic started by: digit on September 02, 2016, 09:41:38 AM

Title: Tinyscreen+ button interrupts
Post by: digit on September 02, 2016, 09:41:38 AM
I think it should be possible to trigger interrupts using the four buttons on the TinyScreen+.

Code: [Select]
attachInterrupt(digitalPinToInterrupt( ??? ), callback, LOW);
Has anyone done this? I'm not sure what the pins would be  :-\

Thanks
Digit
Title: Re: Tinyscreen+ button interrupts
Post by: Ben Rose on September 04, 2016, 02:59:31 PM
That's right, definitely possible- luckily all the extra IO pins are interrupt capable through the Arduino core. Pins are defined in TinyScreen.h, TSP_PIN_BT1 through TSP_PIN_BT4.

That should be working fine- let me know if you have issues.

Thanks,
Ben
Title: Re: Tinyscreen+ button interrupts
Post by: digit on September 05, 2016, 05:35:56 AM
Thanks Ben!

Some simple test code here to check the button interrupts:

Code: [Select]
#include <TinyScreen.h>

TinyScreen display = TinyScreen(TinyScreenPlus);

void setup() {
  display.begin();
  display.setBrightness(12); //valid levels are 0-15
 
  pinMode(TSP_PIN_BT1, INPUT_PULLUP);
  pinMode(TSP_PIN_BT2, INPUT_PULLUP);
  pinMode(TSP_PIN_BT3, INPUT_PULLUP);
  pinMode(TSP_PIN_BT4, INPUT_PULLUP);
 
  attachInterrupt(digitalPinToInterrupt(TSP_PIN_BT1), fillScreen, RISING);
  attachInterrupt(digitalPinToInterrupt(TSP_PIN_BT2), fillScreen, RISING);
  attachInterrupt(digitalPinToInterrupt(TSP_PIN_BT3), fillScreen, RISING);
  attachInterrupt(digitalPinToInterrupt(TSP_PIN_BT4), fillScreen, RISING);
 
  randomSeed(analogRead(0));
}

void loop() {
  //Other code here....
  delay(1000);
}

void fillScreen() {
  // Draw a rectangle the same size as the screen and fill it with a color.
  // drawRect(x, y, w, h, fill (0 or 1), r, g, b)
  display.drawRect(0, 0, display.xMax, display.yMax, 1,random(255),random(255),random(255));
}

I'm not sure if the internal pullups are completely necessary, or that display.xMax and display.yMax is the best way to set the screen size. But this might be useful for someone.

Also, I'm surprised there isn't a display.getWidth() and display.getHeight() method in TinyScreen.h. It could be quite useful.

Thanks
Digit