Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

NeoTrellis key press to Serial monitor
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

NeoTrellis key press to Serial monitor

by Moris526 on Fri Mar 13, 2020 11:30 pm

Hi.

I want to send the pixel/button number of the neotrellis to the serial monitor.

In the ¨interrupt¨ example from the Seesaw Library I see it should be done in the ¨TrellisCallback¨ part.

I can serial.write a number every time a button is pressed, but i dont know how to get the particular button/pixel .

I leave the code
thanks

Code: Select all | TOGGLE FULL SIZE
/* This example shows basic usage of the NeoTrellis
  with the interrupt pin.
  The buttons will light up various colors when pressed.
*/

#include "Adafruit_NeoTrellis.h"

Adafruit_NeoTrellis trellis;

#define INT_PIN 10

// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return trellis.pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return trellis.pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return trellis.pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

//define a callback for key presses
TrellisCallback blink(keyEvent evt){
 
  if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING)
    trellis.pixels.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, trellis.pixels.numPixels(), 0, 255))); //on rising
  else if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING)
    trellis.pixels.setPixelColor(evt.bit.NUM, 0); //off falling
   
  trellis.pixels.show();
  return 0;
}

void setup() {
  Serial.begin(9600);
  //while(!Serial);

  pinMode(INT_PIN, INPUT);
 
  if(!trellis.begin()){
    Serial.println("could not start trellis");
    while(1);
  }
  else{
    Serial.println("trellis started");
  }

  //activate all keys and set callbacks
  for(int i=0; i<NEO_TRELLIS_NUM_KEYS; i++){
    trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING);
    trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING);
    trellis.registerCallback(i, blink);
  }

  //do a little animation to show we're on
  for(uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
    trellis.pixels.setPixelColor(i, Wheel(map(i, 0, trellis.pixels.numPixels(), 0, 255)));
    trellis.pixels.show();
    delay(50);
  }
  for(uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
    trellis.pixels.setPixelColor(i, 0x000000);
    trellis.pixels.show();
    delay(50);
  }
}

void loop() {
  if(!digitalRead(INT_PIN)){
    trellis.read(false);
  }
  delay(2);
}

Moris526
 
Posts: 45
Joined: Fri Jan 17, 2020 10:09 am

Re: NeoTrellis key press to Serial monitor

by dastels on Mon Mar 16, 2020 11:16 am

It's there in the code: evt.bit.NUM

Dave

dastels
 
Posts: 3767
Joined: Tue Oct 20, 2015 3:22 pm

Re: NeoTrellis key press to Serial monitor

by Moris526 on Wed Mar 18, 2020 12:06 am

Yes.
In serial monitor of arduino appeared empty little squares.
But if i use the max msp serial i get the ascii numbers.
Thnaks

Moris526
 
Posts: 45
Joined: Fri Jan 17, 2020 10:09 am

Re: NeoTrellis key press to Serial monitor

by dastels on Wed Mar 18, 2020 9:00 am

Hmm. The serial monitor seems to be trying to display as a character, maybe?

dastels
 
Posts: 3767
Joined: Tue Oct 20, 2015 3:22 pm

Re: NeoTrellis key press to Serial monitor

by Moris526 on Wed Mar 18, 2020 5:54 pm

I guess. Theres a button that displays a Spades from poker cards.

Anyway. I needed to send data to max, and that works fine.

Your answer gave me the idea of checking that.

I ask you another question, just in case you know.

Im trying to supply the adafruit with external power. I try different 5v chargers with no luck.
Any idea?

Thanks.

Moris526
 
Posts: 45
Joined: Fri Jan 17, 2020 10:09 am

Re: NeoTrellis key press to Serial monitor

by dastels on Wed Mar 18, 2020 7:18 pm

What have you tried?

dastels
 
Posts: 3767
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.