Main sketch:
#include <UTFT.h>
#include <UTouch.h>
#include "Comms.h"
#include "Menus.h"
Comms comms;
Menus menus;
int x,y;
char inData[50]; // Allocate some space for the string
char inChar; // Where to store the character read
byte index = 0; // Index into array; where to store the character
boolean incoming = false;
String piStatus = "Waiting";
String piIp;
int statPin =A7;
int inPin = 53;
int val = 0;
int statli = 0;
int pstatli = 0;
int count = 0;
void setup()
{
Serial.begin(9600);
Serial1.begin(115200);
Serial3.begin(9600);
statli = analogRead(statPin);
val = digitalRead(inPin);
if (val==1){
piStatus ="Booting";
}
else{
piStatus = "Off";
}
menus.initScrn();
menus.homeScrn();
pinMode(inPin, INPUT);
Serial1.println("ST");
Serial.println("setup Complete");
myGLCD.print("Arduino Status: Ready", LEFT, 14);
}
void loop(){
count ++;
menus.countMe(count);
static char input_line [MAX_INPUT];
static unsigned int input_pos = 0;
int pVal = val;
val = digitalRead(inPin);
pstatli = statli;
if((pVal==0) && (val == 1)){
piStatus ="Booting";
menus.homeScrn();
Serial.println("Val is now 1");
}
if((pVal==1) && (val == 0)){
piStatus ="Off";
menus.homeScrn();
Serial.println("Val is now 0");
}
statli = analogRead(statPin);
menus.updateStatpin(statli);
/*if(piStatus != "Shutting down"){
if((val ==1) && (statli ==0)){
piStatus = "Shutting down";
menus.homeScrn();
}
}*/
if (Serial1.available () > 0) {
comms.piInit();
} // end of incoming data
if (Serial.available()){
int inByte = Serial.read();
Serial1.write(inByte);
}
if (Serial3.available()){
//Serial.print("from remote: ");
int inByteT = Serial3.read();
Serial.write(inByteT);
}
menus.touched();
if(count == 1000){
Serial.println("1,000");
count = 0;
Serial3.println("$Check@");
}
}
Menus:
#include "Arduino.h"
#include "Menus.h"
extern UTFT myGLCD(ITDB32S, 38,39,40,41); // Remember to change the model parameter to suit your display module!
UTouch myTouch(6,5,4,3,2);
void Menus::initScrn(){
// Uncomment the next two lines for the Arduino Mega
// Setup the LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
}
void Menus::homeScrn(){
myGLCD.clrScr();
mnu = 0;
myGLCD.setColor(255, 0, 0);
myGLCD.fillRect(0, 0, 319, 13);
myGLCD.setColor(64, 64, 64);
myGLCD.fillRect(0, 226, 319, 240);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print("* Loren's Operating System *", CENTER, 1);
myGLCD.setBackColor(64, 64, 64);
myGLCD.print("Arduino Status: Setup", LEFT, 14);
String temp(piStatus);
myGLCD.print("PI Status: " + temp, LEFT, 28);
if (piIp != NULL){
Serial.println("IP is not null");
myGLCD.print("Pi IP: " + piIp, LEFT,42);
}
myGLCD.setColor(0,0,255);
myGLCD.fillRoundRect(10,200,70,230);
myGLCD.setColor(255,255,255);
myGLCD.drawRoundRect(10,200,70,230);
myGLCD.setBackColor(0,0,255);
myGLCD.print("Menu", 25,210);
}
void Menus::touched(){
if (myTouch.dataAvailable()){
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
//Bottom row
if ((y>=200) && (y<=240)){
//first column
if((x>=10) && (x<=70)){
if(mnu == 0){
menuScrn();
}
else if(mnu ==1){
homeScrn();
}
}//first column end
//second column
if ((x>=80) && (x<=140)){
if (mnu == 1){
Serial1.println("SD");
Serial.println("shut down");
piStatus = "Shutting Down";
mnu = 0;
homeScrn();
//delay(50);
}//end mnu ==1
}//end second column
if ((x>=150) && (x<=210)){
if (mnu == 1){
Serial1.println("RB");
Serial.println("Restart");
piStatus = "Restarting";
piIp = NULL;
mnu = 0;
homeScrn();
}//end mnu ==1
}//end third column
if ((x>=220) && (x<=270)){
if (mnu == 1){
Serial1.println("VN");
Serial.println("vnc");
mnu = 0;
homeScrn();
//delay(50);
}//end mnu ==1
}//end second column
delay(75);
}
}
}
void Menus::menuScrn(){
mnu = 1;
myGLCD.clrScr();
myGLCD.setColor(255, 0, 0);
myGLCD.fillRect(0, 0, 319, 13);
myGLCD.setColor(64, 64, 64);
myGLCD.fillRect(0, 226, 319, 240);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print("* Loren's Operating System *", CENTER, 1);
//Buttons
myGLCD.setColor(0,0,255);
myGLCD.fillRoundRect(10,200,70,230);
myGLCD.setColor(255,255,255);
myGLCD.drawRoundRect(10,200,70,230);
myGLCD.setBackColor(0,0,255);
myGLCD.print("Home", 25,210);
myGLCD.setColor(0,0,255);
myGLCD.fillRoundRect(80,200,140,230);
myGLCD.setColor(255,255,255);
myGLCD.drawRoundRect(80,200,140,230);
myGLCD.setBackColor(0,0,255);
myGLCD.print("Quit", 95,210);
myGLCD.setColor(0,0,255);
myGLCD.fillRoundRect(150,200,210,230);
myGLCD.setColor(255,255,255);
myGLCD.drawRoundRect(150,200,210,230);
myGLCD.setBackColor(0,0,255);
myGLCD.print("Restart", 154,210);
myGLCD.setColor(0,0,255);
myGLCD.fillRoundRect(220,200,270,230);
myGLCD.setColor(255,255,255);
myGLCD.drawRoundRect(220,200,270,230);
myGLCD.setBackColor(0,0,255);
myGLCD.print("VNC", 228,210);
}
void Menus::updateStatpin(int stat){
String statTemp(stat);
myGLCD.print("Status pin: " + statTemp, LEFT, 56);
}
void Menus::countMe(int count){
String temp(count);
myGLCD.print("Count: " + temp, LEFT, 70);
}
Serial 1 = Raspberry pi
Serial 3 = Arduino Uno via Xbee
Serial1.println("ST"); would call a function on the PI to see if the PI had powered up before the arduino. If nothing is returned then the mega just continues waiting for the Pi to boot. If the PI did start before the mega the command recieved by the pi will then will go through a routine to relay some information to the Arduino.