// Project#1 - Pycharm, pyseril, and Arduino comms (LCD readout)
// Setup instructions:  
// Place jumpers across all 8 LCD header connections (See project video)

#include "LiquidCrystal.h"      // INCLUDE THE LIBRARY THAT HELPS TO DRIVE THE LCD.
LiquidCrystal lcd(2,3,4,5,6,10);// LCD pins RS/E/D4/D5/D6/D7 connected to UNO pins 2,3,4,5,6,10 Respectively.  USING THE LCD QUICK-CONNECT DIP SWITCH DOES ALL OF THIS FOR YOU ON CHIP-A
#define LCD_EN 11               // LCD Backlight controller definition
byte incomingByte = 0x00;       // Create a byte variable named "incomingByte".  The data we receive from the PC will be stored here.


void setup() {
  lcd.begin(16,02);              // THIS SETS UP THE LCD, WHICH CAN SHOW 16 CHARACTERS ACROSS TWO LINES
  lcd.clear();                   // CLEAR THE LCD
  pinMode(LCD_EN,OUTPUT);        // Declare LCD_EN as an output
  digitalWrite(LCD_EN,HIGH);     // Turn the LCD backlight on
  lcd.print("Project#1!");       // Print this to the top line of the LCD
  Serial.begin(115200);          // Start the serial monitor / enable serial prints to the PC at a baud rate of 115200
}



void loop(){   // This is the main loop.  It will look over and over until the PPRInoRPI powers down                        
    while (Serial.available() > 0) {    // If a serial communcation from the PC has been received, do the following:
    incomingByte = Serial.read();       // Read it and store it in 'incomingByte'
    lcd.clear();                        // Clear the LCD
    lcd.print("Incoming:");             // Print this to the top line of the LCD
    lcd.print(incomingByte);            // Print the incoming byte value.  Remember, we'll see the ASCII version, not the decimal version.
    // So if the PC sends 5, the RPInoRPI will read the ASCII version of decimal 0, which is 48, or 5, which is 53.  
    // Check out this table: https://www.rapidtables.com/code/text/ascii-table.html
  }
}
   
    