/* Pacman Ghost Costume - shifty eyes MASTER 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 WHITE 0xFFFF
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() {
    Serial.print('1');// tell slave to start it's cycle
    for ( i = 0; i < maxS; i++) { // shift left to right
      tft.vertScroll(0, 320, i);
      delay(5);
    }  
    delay(8);
    for ( i = maxS; i > 0; i--) {// shift right to left
      tft.vertScroll(0, 320, i);
      delay(5);
    }   
  delay(150);// pause before next cycle
}
