/*DueAck1_Tx_Touch
19 Sept 2018 add touch buttons.
18 Sept 2018 Do graphics
Edited: 31 Sept 2018 16 Sept 2018
DUE & 2.8" TFT 240x320 Uno shield ILI9341 multi wire
MultiTxAckPayload - the master or the transmitter (Tx)
works with two or more(max6) Arduinos (Rx) as slaves.
The Tx use this SimpleRxAckPayload program to request
2 values after each request.
example address for Tx-{'R','x','A','A','A'}
and {'R','x','A','A','B'}
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 50 //nrf24
#define CSN_PIN 51 //nrf24
#include <MCUFRIEND_kbv.h>
//#include <Adafruit_GFX.h> //already called in MCUFRIEND
#include<TouchScreen.h>
MCUFRIEND_kbv tft;
#include<Fonts/FreeMono9pt7b.h>
#define LCD_CS A3//shared pins XM
#define LCD_CD A2//shared pins YP
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
//T.S allignment
#define TS_MINX 40
#define TS_MINY 40
#define TS_MAXX 1000
#define TS_MAXY 1000
#define YP A2 // shared pin CD
#define XM A3 // shared pin CS
#define YM 8
#define XP 9
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define LIGHTGREY 0xDEDB
#define GREY 0xCE79
//indicates number of slaves, see addresses below in { }
const byte numSlaves = 3; //Maximum 6 units
const byte slaveAddress[numSlaves][5] = {
{'R', 'x', 'A', 'A', 'A'}, //address for Unit 1
{'R', 'x', 'A', 'A', 'B'}, //address for Unit 2
{'R', 'x', 'A', 'A', 'F'}, //address for Unit 3
};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
char dataToSend[32] = "Unit: "; //this [32] must match dataReceived from Rx
float ackData[2] = { -11.11, -11.11}; // to hold the two values coming from the Unit
bool newData = false;
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 5000;
#define MINPRESSURE 100
#define MAXPRESSURE 1000
// ( 9, A2, A3, 8,RESISTANCE)
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 365);
int X, Y, Z;
void setup() {
Serial.begin(9600);
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.enableAckPayload();
radio.setRetries(10, 8); // delay, count
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
tft.setRotation(1); //power supply port is bottom right
tft.fillScreen(BLACK);
tft.setFont(&FreeMono9pt7b); //set new font
}
void loop() {
pinMode(LCD_CS, OUTPUT); //shared pins
pinMode(LCD_CD, OUTPUT); //shared pins
tft.setCursor(1, 30);
Serial.println("txInterval");
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
//clear the previouse readings before the new set is printed
tft.fillRect(0, 8, 320, 100, BLACK); //left,top,width,height,color
tft.drawRect(-1, 9, 320, 35, WHITE); //amps 1
tft.drawRect(-1, 45, 320, 35, WHITE); //amps 2
tft.drawRect(-1, 81, 320, 35, WHITE); //amps3
tft.drawRect(-1, 116, 320, 35, WHITE); //amps4
tft.drawRect(3, 170, 75, 35, WHITE); //button 1
sendB();
}//if (currentMil
TSPoint p = ts.getPoint();
if (p.z > ts.pressureThreshhold) {
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//GFX.h x=width and y=height
//X = tft.width() - map(p.x, TS_MINX, TS_MAXX,tft.width(),0 );
//Y = map(p.y, TS_MINY, TS_MAXY, tft.height() ,0 );
X = 320 - map(p.x, TS_MAXX, TS_MINX, 320, 0 );
Y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
Z = p.z;
//Button co-ords for button T.S
if (X > 3 && X < 78 && Y > 160 && Y < 190) {
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillScreen(BLACK);
Serial.println("send A");
sendA();
}//if (X > 3
}//if( p.z
}//end loop
void sendB() {
for (byte n = 0; n < numSlaves; n++) { // call each Unit in turn
radio.openWritingPipe(slaveAddress[n]);
// include the Unit number in the message
dataToSend[5] = n + '1'; //start 'unit no' at 1
bool rslt;
rslt = radio.write( &dataToSend, sizeof(dataToSend) );
if (rslt) {
if ( radio.isAckPayloadAvailable() ) {
radio.read(&ackData, sizeof(ackData));
newData = true;
}
}
if (newData == true) {
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.print(dataToSend); //prints 'Unit ' + unit ID
tft.print(" ");
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.print(ackData[0]); // the value ONLY
tft.print(", Volts: ");
tft.println(ackData[1]); // the value ONLY
tft.println();
newData = false;
}
}
prevMillis = millis();
}
void sendA() {
Serial.println("Button pressed");
}
Members
The program get a reading roughly every 5 sec from 3 units. The readings are displayed correctly.
The problem is when I press the TS button the screen is erased/goes dark/blank for about 3 sec. The problem is with the shared pins. The graphics & the touch screen share 2 pins and that create the issue.
I have tried a few other programming options but did not come up with a solution. Any help would be appreciated.
Thanks.