#include <FastLED.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <EEPROM.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const uint8_t ROWS = 4; // number of rows in the keyboard
const uint8_t COLS = 4; // number of collumns in the keypad
char keys[ROWS][COLS] = { // the keypad charater matrix (there are 4 nul keys)
{ 1, 2, 3, '>' }, // top row numbers 1 to 3 and a null
{ 4, 5, 6, '<' }, // 2nd row numbers 4 to 6 and a null
{ 7, 8, 9, 'S' }, // 3rd row numbers 7 to 9 and a null
{ 'R', ' ', 'D', 'U' } // 4th row number 0, a null D for delete and C for clear
};
// note that American Standard Code for Information Interchange (ASCII)
// is used for zero, as zero would be interpreted as no key pressed
uint8_t colPins[COLS] = { A3, A2, A1, A0 }; // Pins connected to collumns 1 to 4
uint8_t rowPins[ROWS] = { 5, 4, 3, 2 }; // Pins connected to rows 1 to 4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// make the keyboard map used by keyboard.h from the above information
byte S1[]={0xC0,0x00,0x02,0x08,0x82,0x8C,0x03,0x00}; //send 1 write
byte S2[]={0xC0,0x00,0x02,0x0A,0x83,0x9F,0x01,0x00,0x03,0xD6}; //send 2 write
byte S3[]={0xC0,0x00,0x02,0x08,0x82,0x9F,0x03,0xD4}; // send 3 read and weite
byte R1[]={0xC0,0x01,0x02,0x0B,0x82,0x9F,0x00,0x08,0x00,0x03,0xDE}; // receive read and write
byte S4[]={0xC0,0x00,0x02,0x08,0x82,0x86,0x03,0xCD}; //send 1 read
byte str[]={" "};
byte testmess[]={"test message"};
byte rc;
int value;
byte recmess[]=" ";
int count;
unsigned long serial;
int length;
int par;
void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
//Serial.begin(1200,SERIAL_8E2); // open the serial port at 9600 bps:
Serial.begin(9600);
//lcd.print("initial test");
}
void loop()
{
lcd.clear();
int par=0;
for(int i=0;i<7; i++)
{
par=par^S1[i];
lcd.print(par,HEX);
}
S1[7]=par;
lcd.setCursor(0,1);
for(int i=0;i<=7; i++)
{
lcd.print (S1[i],HEX);
}
delay(500);
}
/*
{
count=0;
Serial.write(S1,sizeof(S1));
delay (500);
Serial.write(S2,sizeof(S2));
delay (500);
Serial.write(S3,sizeof(S3));
delay (500);
// only for test
Serial.write(R1,sizeof(R1));
delay (500);
// end of test code
length=Serial.available();
lcd.setCursor(0,0);
count=0;
lp:
rc=Serial.read();
recmess[count]=rc;
count++;
if (Serial.available()>0) goto lp;
/*
serial=0;
lcd.print("S.No ");
for (count=length-10;count<=length-7;count++)
{
rc=recmess[count];
serial=serial*256+rc;
//lcd.print(rc);
}
lcd.print(serial);
lcd.setCursor(0,1);
*/
/*
lcd.print("M");
lcd.print(recmess[length-6],HEX);
lcd.print(" Y");
lcd.print(recmess[length-5],HEX);
lcd.print(" T");
lcd.print(recmess[length-4],HEX);
if (recmess[length-3]==161) lcd.print(" VDO");
else
{
lcd.print(" P ");
lcd.print(recmess[length-3],HEX);
}
lcd.print ("Division ratio");
lcd.setCursor(0,1);
lcd.print(" is ");
lcd.print (recmess[length-4],HEX);
lcd.print(":1");
delay(500); // delay 200 milliseconds
}*/