/* Pacman Ghost Costume - shifty eyes SLAVE Version
 *  2019 - Gord Payne
 *  Requires Master and Slave versions
 *  Both Arduinos use mcu_friend 320x240 TFT touchscreens (make sure they are matched pairs)
 *  Wiring
 *  Master          Slave
 *  GND ----------  GND
 *  TX1 ----------  RX0
 */
 #include "Adafruit_GFX.h"
#include "MCUFRIEND_kbv.h"
#define BLACK 0x0000
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define RED 0xF800

int maxS = 180;// vertical scroll limit for left-right shift
MCUFRIEND_kbv tft(A3, A2, A1, A0, A4);
void setup() {
uint16_t ID = tft.readID();
  tft.setRotation(0);
  tft.begin(ID);
  tft.fillScreen(WHITE);
  Serial.begin(9600);// open serial communication
  tft.fillCircle(100, 250, 69, BLACK);// draw eye
    tft.fillRect(0, 180, 100, 140, BLACK);
}

void loop() {
  theChar = Serial.read();
  if (theChar == '1') {// if received a pulse from the MASTER
 
    for (uint16_t i = 0; i < maxS; i++) {// shift left to right
      tft.vertScroll(0, 320, i);
      delay(5);
    }
    delay(10);
    for (uint16_t i = maxS; i > 0; i--) { // shift right to left
      tft.vertScroll(0, 320, i);
      delay(5);
    }
  }
  delay(50); // brief pause
}
