i work in project that use load cell and 2 x 16 lcd
i want to add New Feature
i want add 4x4 kaypad
why ??
i want after arduino read load cell i add number to Divide it with the result
look like
1- arduino read load cell
2-arduino give me the result on lcd
3-me press F1 kay in kaypad
4-enter the number
5-arduino Calculates --> (( the result / number i enter it ))
6- arduino print the new result in lcd
7- press F2 for start again
the code i use
//
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '4', '7', '*'}, // * = Mode
{'2', '5', '8', '0'},
{'3', '6', '9', '#'}, // # = Cancel
{'A', 'B', 'C', 'D'} // A=F1 B=F2 C=F3 D=enter
};
byte rowPins[ROWS] = { 2, 3, 4, 5 };
byte colPins[COLS] = {10, 11, 12, 13 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#include <LiquidCrystal595.h>
LiquidCrystal595 lcd(7,8,9);
#define DT A0 // A/D pin
#define SCK A1 // A/D pin
#define sw 2
long sample=0;
float val=0;
long count=0;
unsigned long readCount(void)
{
unsigned long Count;
unsigned char i;
pinMode(DT, OUTPUT);
digitalWrite(DT,HIGH);
digitalWrite(SCK,LOW);
Count=0;
pinMode(DT, INPUT);
while(digitalRead(DT));
for (i=0;i<24;i++)
{
digitalWrite(SCK,HIGH);
Count=Count<<1;
digitalWrite(SCK,LOW);
if(digitalRead(DT))
Count++;
}
digitalWrite(SCK,HIGH);
Count=Count^0x800000;
digitalWrite(SCK,LOW);
return(Count);
}
void setup()
{
Serial.begin(9600);
pinMode(SCK, OUTPUT);
pinMode(sw, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.print(" hello world");
lcd.setCursor(0,1);
lcd.print("load");
delay(3500);
lcd.clear();
calibrate();
}
void loop()
{
delay(15);
count= readCount();
int w=(((count-sample)/val)-2*((count-sample)/val));
Serial.print("weight:");
Serial.print((int)w);
Serial.println("g");
lcd.setCursor(0,0);
lcd.print("wight = ");
lcd.setCursor(0,1);
lcd.print(w);
lcd.print("g ");
if(digitalRead(sw)==0)
{
val=0;
sample=0;
w=0;
count=0;
calibrate();
}
}
void calibrate()
{
lcd.clear();
lcd.print("Calibrating...");
lcd.setCursor(0,1);
lcd.print("Please Wait...");
for(int i=0;i<100;i++)
{
count=readCount();
sample+=count;
Serial.println(count);
}
sample/=100;
Serial.print("Avg:");
Serial.println(sample);
lcd.clear();
lcd.print(" try");
lcd.setCursor(0,1);
lcd.print(" put 100 g");
count=0;
while(count<1000)
{
count=readCount();
count=sample-count;
Serial.println(count);
}
lcd.clear();
lcd.print(" load");
lcd.setCursor(0,1);
lcd.print("Please Wait....");
delay(2000);
for(int i=0;i<100;i++)
{
count=readCount();
val+=sample-count;
Serial.println(sample-count);
}
val=val/100.0;
// put here your calibrating weight
lcd.clear();
}
//