Hello , I have a project with an Arduino Mega with TFT and Ethernet Shield. I am testing 30 switches, and I want to count the on/off cycles and keep the counters in EEPROM.
The counters should only be reset when having a HIGH at input 53. in the program are only 10 switches for the moment.
Everything was working ok, until calling the ethernet function. Now the server is working, but the EEPROM doesn't keep the counters anymore.
Can you help me with this? Thank You.
/Import Libraries_/
#include <SPFD5408_Adafruit_GFX.h> // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>
#include <EEPROM.h>
#include <Ethernet.h>
#include <SPI.h>
/End of Libraries_/
/Define LCD pins (I have asigned the default values)_/
#define YP A3// A1 // must be an analog pin, use "An" notation!
#define XM A2// A2 // must be an analog pin, use "An" notation!
#define YM 9 //7 // can be a digital pin
#define XP 8 //6 // can be a digital pin
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
/_End of defanitions/
/Assign names to colors and pressure_/
#define WHITE 0x0000 //Black->White
#define YELLOW 0x001F //Blue->Yellow
#define CYAN 0xF800 //Red->Cyan
#define PINK 0x07E0 //Green-> Pink
#define RED 0x07FF //Cyan -> Red
#define GREEN 0xF81F //Pink -> Green
#define BLUE 0xFFE0 //Yellow->Blue
#define BLACK 0xFFFF //White-> Black
#define MINPRESSURE 10
#define MAXPRESSURE 1000
/_Assigned/
/Calibrate TFT LCD_/
#define TS_MINX 220//125
#define TS_MINY 100//85
#define TS_MAXX 848//965
#define TS_MAXY 850//905
/End of Calibration/
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); //300 is the sensitivity
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //Start communication with LCD
/////////////////////////////////////////////////////////////////////////////////////////////
//Ethernet communication
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 2, 100 }; // ip in lan
//byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
int n[]={22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52} ;//array of inputs 22->52;
int state[30];//array of inputs state
int Lstate[30];//array of inputs last state
int k[30];//array of counters
int i,j;
const int res = 53; //RESET SWITCH
int ButReset =0;
void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
for(i=0;i<10;i++)
{ pinMode(n*,INPUT);*
-
}*
-
pinMode(res,INPUT); //intrare de reset counteri to zero;*
-
tft.reset(); //Always reset at start*
-
tft.begin(0x9325); // My LCD uses LIL9341 Interface driver IC*
-
tft.setRotation(3); // I just rotated so that the power jack faces up - optional*
-
tft.fillScreen(WHITE);*
-
//initialization last state*
-
for (i=0;i<10;i++)*
{ Lstate_= digitalRead(n*);
}
///////////counter reading*
* for (i=0;i<10;i++)
{k=EEPROM.read(i);
}
////////////////////////////Ethernet //////////////////////////
Ethernet.begin(mac, ip);
//Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
/////////////////////////////////////////////////////////////
IntroScreen();_
// draw_BoxNButtons();
_}
void loop()
{
for ( i=0;i<10;i++)
{ state= digitalRead(n);_
if ( state _!= Lstate)
{ k++;
Lstate=state;
EEPROM.write(i, k);
change();
}
}
//eeprom reset procedure
ButReset = digitalRead(res);
if (ButReset == HIGH) {
zero();
}
ENET();*_
* delay(500);/////////////////////////////////////////// for tests*
}
void ENET()
*{ *
* // Create a client connection*
* EthernetClient client = server.available(); *
if (client) {
* while (client.connected())*
* {*
* if (client.available())*
* {*
* client.println("CEZ Lubrication Monitoring ");*
* client.println("*
");
* client.println("Status Injectors: ");*
* for (i=0;i<10;i++)*
* { *
_ client.println((state*));
}
client.println("
");
client.println("Cycles:");
for (i=0;i<10;i++)
{
client.println(k);
}
delay(1);
//stopping client*
* client.stop();
}*_
* }*
}}
void change()
{
* tft.fillRect(0,90,320,140,WHITE);*
* for (i=0;i<10;i++)*
* { *
_ tft.setCursor(32i,110);
tft.setTextSize(2);
tft.setTextColor(BLUE);
tft.println(k);
}
for (i=0;i<10;i++)
{ tft.setCursor(32i,90);
* tft.setTextSize(2);
tft.setTextColor(BLUE);
tft.println(state);
}*_
}
* void zero()*
* {*
* for (i=0;i<10;i++)*
* {*
* EEPROM.write(i,0);*
* }*
* }*
void IntroScreen()
{
* //tft.fillRect(20,90,20,20,WHITE);*
* tft.setCursor (120, 20);*
* tft.setTextSize (4);*
* tft.setTextColor(CYAN);*
* tft.println("CEZ");*
* tft.setCursor (30, 50);*
* tft.setTextSize (2);*
* tft.println("LUBRICATION MONITORING");*
* tft.setCursor (70, 70);*
* tft.setTextSize (2);*
* tft.setTextColor(BLUE);*
* tft.println("ENGINEERING DEPT");*
for (i=0;i<10;i++)
* {*
_ tft.setCursor(32i,90);
tft.setTextSize(2);
tft.setTextColor(BLUE);
tft.println(digitalRead(n));
}
for (i=0;i<10;i++)
{
tft.setCursor(32i,110);
* tft.setTextSize(2);
tft.setTextColor(BLUE);
tft.println(k);
}
}
void draw_BoxNButtons()
{
//Draw the Result Box*
* //Draw Vertical Lines*
* for (int h=87; h<=300; h+=20)
tft.drawFastHLine(0, h, 300, BLACK);
//Draw Vertical Lines*
* for (int v=0; v<=300; v+=27)
tft.drawFastVLine(v, 90, 140, BLACK);
}
LUBRICATION.ino (5.79 KB)*_