//Saline Level Alert Program
// Hx711.DOUT - pin #A2
// Hx711.SCK - pin #A3
#include <Hx711.h>
#include "LedControl.h"
Hx711 scale(A2,A3);
int buzzer=9;
int selectPin = 8; // select the input pin for the toggle switch
int ledPin500 =10; // select the pin for the LED
int ledPin100 =11;
int val = 0; // variable to store the value coming from the sensor
int volume=500;
LedControl lc=LedControl(5,7,6,0); // Pin 5 to Data In, 7 to Clk, 6 to LOAD(orCS)
void setup(){
Serial.begin(9600);
pinMode(buzzer,OUTPUT);
pinMode(ledPin100, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(ledPin500,OUTPUT);
pinMode(selectPin,OUTPUT);
digitalWrite(buzzer,0);
lc.shutdown(0,false);// turn off power saving, enables display
lc.setIntensity(0,0);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
}
void loop() {
val = digitalRead(selectPin); // read the value from the select pin
// Serial.println(val);
// int volume=0;
float weight = scale.getGram();
if(weight<0)
{
weight=0;
}
Serial.print(weight,1);
delay(10000);
Serial.println("");
//Serial.print(scale.getGram(), 1);
// Serial.println(" g");
if(val==0) //if((weight>=15)||val==0)
{
volume=100;
Disp_Data100();
digitalWrite(ledPin100, HIGH); // turn the ledPin on
if ((weight<=160)&&(weight>=110))
{
// lc.setChar(0,4,'F',false);
lc.setChar(0,3,'H',false);
lc.setDigit(0,2,1,false);
lc.setDigit(0,1,6,false);
lc.setChar(0,0,'H',false);
}
else if ((weight<110)&&(weight>=80))
{
// lc.setChar(0,4,'H',false);
lc.setChar(0,3,'H',false);
lc.setChar(0,2,'A',false);
lc.setChar(0,1,'L',false);
lc.setChar(0,0,'F',false);
}
else if (weight<80)
{
lc.setChar(0,3,'L',false);
lc.setChar(0,2,'E',false);
lc.setDigit(0,1,5,false);
lc.setDigit(0,0,5,false);
}
else if ((weight<80 && weight>77)||(weight<65 && weight>45))
{
digitalWrite(buzzer,HIGH);
// lc.setChar(0,4,'L',false);
}
else
{
digitalWrite(buzzer,LOW);
}
}
else
{
digitalWrite(ledPin100, LOW);
} // stop the program for some time
if(val==1)
{
volume=500;
digitalWrite(buzzer,0);
Disp_Data500();
digitalWrite(ledPin500, HIGH); // turn the ledPin on
digitalWrite(ledPin100,LOW);
if ((weight<=555)&&(weight>=350))
{
// lc.setChar(0,4,'F',false);
lc.setChar(0,3,'H',false);
lc.setDigit(0,2,1,false);
lc.setDigit(0,1,6,false);
lc.setChar(0,0,'H',false);
}
else if ((weight<350)&&(weight>=110))
{
// lc.setChar(0,4,'H',false);
lc.setChar(0,3,'H',false);
lc.setChar(0,2,'A',false);
lc.setChar(0,1,'L',false);
lc.setChar(0,0,'F',false);
}
else if((weight<110))
{
// lc.setChar(0,4,'L',false);
lc.setChar(0,3,'L',false);
lc.setChar(0,2,'E',false);
lc.setDigit(0,1,5,false);
lc.setDigit(0,0,5,false);
}
else if ((weight<110 && weight>105)||(weight<80 && weight>50))
{
digitalWrite(buzzer,HIGH);
}
else
{
digitalWrite(buzzer,0);
}
}
else
{
digitalWrite(ledPin500, LOW);
}
}
void Disp_Data100(){
int ones, tens,huns;
ones = 0;
tens = 0;
huns=1;
lc.setDigit(0,7,(byte)huns,false);
lc.setDigit(0,6,(byte)tens,false);
lc.setDigit(0,5,(byte)ones,true);
lc.setChar(0,3,' ',false);
lc.setChar(0,2,' ',false);
lc.setChar(0,1,' ',false);
lc.setChar(0,0,' ',false);
}
void Disp_Data500(){
int ones,tens,huns;
ones = 0;
tens = 0;
huns=5;
lc.setDigit(0,7,(byte)huns,false);
lc.setDigit(0,6,(byte)tens,false);
lc.setDigit(0,5,(byte)ones,true);
lc.setChar(0,3,' ',false);
lc.setChar(0,2,' ',false);
lc.setChar(0,1,' ',false);
lc.setChar(0,0,' ',false);
}
/*net weight(full)
500ml= 555g,
100ml= 17g
net weight (half)
500ml= 350g
100ml= 11g
net weight (empty)
500ml= 10.5g to 10.2g(low buzzer) ,8g ,52g
100ml= 8g-7.7g ,6.5g ,42g
net weight (500ml) at threshold-1*/
--