Tinyscreen+ button interrupts

digit · 3 · 5996

digit

  • Newbie
  • *
    • Posts: 2
    • View Profile
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


Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 392
    • View Profile
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


digit

  • Newbie
  • *
    • Posts: 2
    • View Profile
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


 

SMF spam blocked by CleanTalk