TFT 2.4 + UNO + Neopixel LED Ring

Hi All,

I am building a light ring for my DSLR using a 24 LED Neopixel ring.

What i want to achieve is to use a UNO with a TFT 2.4 touchscreen to change the color/intensity of the light.

I found a sketch doing this with a MEGA2560, but was unable to have it work....

TFT tested with the sample sketchs in Arduino IDE, works fine on bot Uno and MEGA 2560.

Didi anyone build something similar and is ready to share the sketch?

Here is the sketch for the MEGA (Which does not work on my side).

Sketch was found there

Thanks for your help!

#include <Adafruit_NeoPixel.h>

#include <math.h>

#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library

#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library

#include <SPFD5408_TouchScreen.h>

// *** SPFD5408 change -- End

#if defined(__SAM3X8E__)

#undef __FlashStringHelper::F(string_literal)

#define F(string_literal) string_literal

#endif

#define YP A1  // must be an analog pin, use "An" notation!

#define XM A2  // must be an analog pin, use "An" notation!

#define YM 7   // can be a digital pin

#define XP 6   // can be a digital pin

#define PIN 53

#define NUM_LEDS 24

#define BRIGHTNESS 80

// Calibrate values

#define TS_MINX 125

#define TS_MINY 85

#define TS_MAXX 965

#define TS_MAXY 905

// For better pressure precision, we need to know the resistance

// between X+ and X- Use any multimeter to read it

// For the one we're using, its 300 ohms across the X plate

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3

#define LCD_CD A2

#define LCD_WR A1

#define LCD_RD A0

// optional

#define LCD_RESET A4

// Assign human-readable names to some common 16-bit color values:

#define  BLACK   0x0000

#define YELLOW    0x001F

#define GREEN     0xF800

#define RED   0x07E0

#define CYAN    0x07FF

#define MAGENTA 0xF81F

#define BLUE  0xFFE0

#define WHITE   0xFFFF

void EmitCyan();

void  EmitWhite();

void  EmitGreen();

void EmitYellow();

void EmitPink();

void  EmitBlack();

uint16_t width = 0;

uint16_t height = 0;

uint16_t x = 40;

uint16_t y = height - 20;

uint16_t w = 75;

uint16_t h = 20;

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

#define BOXSIZE 40

#define PENRADIUS 3

#define BUTTONS 9

#define BUTTON_Red 0

#define BUTTON_DarkRed 1

#define BUTTON_RED 2

#define BUTTON_DarkGreen 3

#define BUTTON_DeepRed 4

#define BUTTON_Blue 5

#define BUTTON_LightBlue 6

#define BUTTON_LightBlue1 7

Adafruit_GFX_Button buttons[BUTTONS];

uint16_t buttons_y = 0;

#define MINPRESSURE 10

#define MAXPRESSURE 1000

void setup() {

  // put your setup code here, to run once:

  Serial.begin(9600);

  Serial.println(F("Paint!"));

  tft.reset();

  tft.begin(0x9341); // SDFP5408

  strip.begin();

  strip.show(); // Initialize all pixels to 'off'

  tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial

  tft.fillScreen(BLACK);

  tft.setCursor (40, 20);

  tft.setTextSize (5);

  tft.setTextColor(WHITE);

  tft.println("COLORS");

  tft.setCursor (65, 85);

  width = tft.width() - 1;

  height = tft.height() - 100;

  initializeButtons();

  showCalibration();

}

void loop() {

  // put your main code here, to run repeatedly:

  // Test of calibration

  

  int i = 0;

  TSPoint p;

  // Wait a touch

  digitalWrite(13, HIGH);

  p = waitOneTouch();

  digitalWrite(13, LOW);

  p.x = mapXValue(p);

  p.y = mapYValue(p);

  for (uint8_t b = 0; b <BUTTONS; b++) {

    if (buttons[b].contains(p.x, p.y)) {

    // Action

    switch  (b) {

    case BUTTON_Red:

        EmitPink();

        showCalibration();

      break;

    case BUTTON_DarkRed:

        EmitCyan();

        showCalibration();

      break;

      

    case BUTTON_RED:

        EmitBlack();

        showCalibration();

      break;

      

    case BUTTON_DarkGreen:

        EmitGreen();

        showCalibration();

      break;

 

    case BUTTON_Blue:

       EmitBlue();

       showCalibration();

      break;

      

    case BUTTON_LightBlue:     

       EmitYellow();

       showCalibration();    

      break;

      

    case BUTTON_DeepRed:    

       EmitDeepRed();       

       showCalibration();         

      break;

    }

  }

}

}

void initializeButtons() {

  uint16_t x = 40;

  uint16_t y = height - 20;

  uint16_t w = 75;

  uint16_t h = 40;

  uint8_t spacing_x = 5;

  uint8_t textSize = 2;

  char buttonlabels[7][20] = {"PINK", "CYAN", "WHITE", "GREEN", "RED", "BLUE", "YELLOW"};

  uint16_t buttoncolors[15] = {RED, GREEN, BLACK, MAGENTA, CYAN, BLUE, YELLOW};

  for (uint8_t b = 0; b < 9; b++) {

    if (b < 3)

    {

      buttons[b].initButton(&tft,                           // TFT object

                            x + b * (w + spacing_x), y,            // x, y,

                            w, h, BLACK, buttoncolors[b], WHITE,    // w, h, outline, fill,

                            buttonlabels[b], textSize);

      Serial.print(  h);

    }// text

    if (b == 3)

    {

      uint16_t x = 40;

      uint16_t y = height + 30 ;

      uint16_t w = 75;

      uint16_t h = 40;

      buttons[b].initButton(&tft,                           // TFT object

                            x + 0 * (w + spacing_x) , y,          // x, y,

                            w, h, BLACK, buttoncolors[b], WHITE,    // w, h, outline, fill,

                            buttonlabels[b], textSize);

    }

    if (b == 4)

    {

      uint16_t x = 40;

      uint16_t y = height + 30 ;

      uint16_t w = 75;

      uint16_t h = 40;

      buttons[b].initButton(&tft,                           // TFT object

                            x + 1 * (w + spacing_x) , y,          // x, y,

                            w, h, BLACK, buttoncolors[b], WHITE,    // w, h, outline, fill,

                            buttonlabels[b], textSize);

    }

    if (b == 5)

    {

      uint16_t x = 40;

      uint16_t y = height + 30 ;

      uint16_t w = 75;

      uint16_t h = 40;

      buttons[b].initButton(&tft,                           // TFT object

                            x + 2 * (w + spacing_x) , y,          // x, y,

                            w, h, BLACK, buttoncolors[b], WHITE,    // w, h, outline, fill,

                            buttonlabels[b], textSize);

    }

    if (b == 6)

    {

      uint16_t x = 40;

      uint16_t y = height + 80 ;

      uint16_t w = 75;

      uint16_t h = 20;

      buttons[b].initButton(&tft,                           // TFT object

                            x + 0 * (w + spacing_x) , y,          // x, y,

                            w, h,BLACK, buttoncolors[b], WHITE,    // w, h, outline, fill,

                            buttonlabels[b], textSize);

    }

    if (b == 7)

    {

      uint16_t x = 40;

      uint16_t y = height + 80 ;

      uint16_t w = 75;

      uint16_t h = 40;

      buttons[b].initButton(&tft,                           // TFT object

                            x + 2 * (w + spacing_x) , y,          // x, y,

                            w, h,BLACK, buttoncolors[b], WHITE,    // w, h, outline, fill,

                            buttonlabels[b], textSize);

    }

  }

  // Save the y position to avoid draws

   buttons_y = y;

}

// Map the coordinate X

uint16_t mapXValue(TSPoint p) {

  uint16_t x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());

  //Correct offset of touch. Manual calibration

  //x+=1;

  return x;

}

uint16_t mapYValue(TSPoint p) {

  uint16_t y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());

  //Correct offset of touch. Manual calibration

  //y-=2;

  return y;

}

TSPoint waitOneTouch() {

  TSPoint p;

  do {

    p = ts.getPoint();

    pinMode(XM, OUTPUT); //Pins configures again for TFT control

    pinMode(YP, OUTPUT);

  } while ((p.z < MINPRESSURE ) || (p.z > MAXPRESSURE));

  return p;

}

void showCalibration() {

  tft.setCursor (40, 0);   

      for (uint8_t i = 0; i < 8; i++) {

        buttons[i].drawButton();

    }

  }

void  EmitDeepRed()

{

  for(int i=0;i<30;i++)

  {

  strip. setPixelColor(i, 255, 0, 0);

  strip.show();

  }

}

void  EmitCyan()

{

  for(int i=0;i<30;i++)

  {

  strip. setPixelColor(i,0, 255, 255);

  strip.show();

  }

}

void  EmitWhite()

{

  for(int i=0;i<30;i++)

  {

  strip. setPixelColor(i,255, 255, 255);

  strip.show();

  }

}

void  EmitGreen()

{

  for(int i=0;i<30;i++)

  {

  strip. setPixelColor(i,0, 255, 0);

  strip.show();

  }

}

void  EmitBlue()

{

  for(int i=0;i<30;i++)

  {

  strip. setPixelColor(i,0, 0, 255);

  strip.show();

  }

}

void  EmitYellow()

{

  for(int i=0;i<30;i++)

  {

  strip. setPixelColor(i,255, 255, 0);

  strip.show();

  }

}

void  EmitPink()

{

  for(int i=0;i<30;i++)

  {

  strip. setPixelColor(i,255, 0, 255);

  strip.show();

  }

}

void  EmitBlack()

{

  for(int i=0;i<30;i++)

  {

  strip. setPixelColor(i,255, 255, 255);

  strip.show();

  }

}


What does the "not working" look like? All LED black, turned to smoke or what? The same question about the display......
Schematics had been nice as well as datasheet for the display.

The sketch uploads fine ont the MEGA but i then got a blank screen,,,

The TFT shield is this one

All tests/example sketch are working properly with the MCUFRIEND_kbv librairy both on the UNO and the MEGA.

Okey, good.
Things work separately but not together. What happens if You connect the lot and run the different test examples?

Why not use that library for the full project?

My Arduino skills are limited, usually, i find a sketch that fits my needs, and then I tweak the code and change the pins numbers....

That's okey. Please reply to #4.

test examples are running fine with the TFT, both on Mega and Uno

Then it looks like the library is not compatible with the other libs.

And I have no clue on how to adapt the code to use the MCUFRIEND Lib....

The final goal would be to have sliders on the tft for the RGB value, a slider for general intensity, and a few presets to choose from..

Look into the working examples and discover which library functions are used and how they are used.
Put the project on the shelf until You get the hardware functioning.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.