The Smell of Molten Projects in the Morning

Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.

Adafruit Touch-screen TFT LCD Rotation

The alert reader will have noted that the Kenmore 158 UI twisted around to a new orientation atop its fancy holder, with the USB port now poking out from the right side:

Kenmore 158 UI - PCB holder
Kenmore 158 UI – PCB holder

That lets me position the whole affair to the right of the sewing machine, in what seems to be its natural position, without having the cable form a loop that would push it off the platform. It’s not entirely clear how we’ll keep a straight cable from pulling it off, but that’s in the nature of fine tuning.

Anyhow, rotating the LCD isn’t a big deal, because the Adafruit library does all the heavy lifting:

// LCD orientation: always landscape, 1=USB upper left / 3=USB lower right
#define LCDROTATION 3

... snippage ...
tft.begin();
tft.setRotation(LCDROTATION);	// landscape, 1=USB upper left / 3=USB lower right

Flipping the touch screen coordinates required just interchanging the “to” bounds of the map() functions, with a conditional serving as institutional memory in the not-so-unlikely event I must undo this:

#if LCDROTATION == 1
	p->x = map(t.y, TS_Min.y, TS_Max.y, 0, tft.width());	// rotate & scale to TFT boundaries
	p->y = map(t.x, TS_Min.x, TS_Max.x, tft.height(), 0);	//   ... USB port at upper left
#elif LCDROTATION == 3
	p->x = map(t.y, TS_Min.y, TS_Max.y, tft.width(), 0);	// rotate & scale to TFT boundaries
	p->y = map(t.x, TS_Min.x, TS_Max.x, 0, tft.height());	//   ... USB port at lower right
#endif

And then It Just Worked.

Comments

2 responses to “Adafruit Touch-screen TFT LCD Rotation”

  1. Kenmore 158: Crash Test Dummy Installation | The Smell of Molten Projects in the Morning Avatar

    […] the UI data/power cable to the motor & LED / sensor cables from the sewing machine keeps the Arduino Mega + TFT from falling off the tabletop, but the arrangement reeks of […]

  2. Kenmore 158 UI: Button Rework | The Smell of Molten Projects in the Morning Avatar

    […] LCD screen looks just like that; I blew out the contrast on the surroundings to provide some context. The […]