#include #include #include #include #include #include int masu = 85; //weight of masu int sake = 18; //weight of sake int pour = 0; HX711 scale1; #define scale1_DOUT 3 #define scale1_SCK 2 float calibration_factor1 = -445; int weight1 = 0; HX711 scale2; #define scale2_DOUT 5 #define scale2_SCK 4 float calibration_factor2 = -1200; int weight2 = 0; HX711 scale3; #define scale3_DOUT 1 #define scale3_SCK 0 float calibration_factor3 = 1170; int weight3 = 0; int ledPin = 12; // LED connected to digital pin 12 int switchPin = A0; // Switch to behave scale weight........................add Servo myservo1; // create servo1 object to control a servo Servo myservo2; // create servo2 object to control a servo int pos = 0; // change the servo degrees int pos_now = 1; int Liquid_level = 0; // received liquid_level from Secondary..............add //int int_x = 0; // .........................................................add void setup() { Serial.begin(9600); scale1.begin(scale1_DOUT, scale1_SCK); scale1.set_scale(); scale1.tare(); //Reset the scale to 0 scale2.begin(scale2_DOUT, scale2_SCK); scale2.set_scale(); scale2.tare(); //Reset the scale2 to 0 scale3.begin(scale3_DOUT, scale3_SCK); scale3.set_scale(); scale3.tare(); //Reset the scale3 to 0 myservo1.attach(8); // attaches the servo1 on pin 8 (PWM) to the servo object myservo2.attach(9); // attaches the servo2 on pin 9 (PWM) to the servo object //Set the servos to initial positions myservo1.write(0); myservo2.write(135); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); //pinMode (switchPin, INPUT_PULLUP); Wire.swap(1); Wire.begin(); } void loop() { Serial.println("Loop"); scale1.set_scale(calibration_factor1); //Adjust to this calibration factor1 scale2.set_scale(calibration_factor2); //Adjust to this calibration factor2 scale3.set_scale(calibration_factor3); //Adjust to this calibration factor3 Serial.print("Scale1_Reading: "); Serial.print(scale1.get_units(), 1); Serial.print("g"); Serial.println(); weight1 = scale1.get_units(); Serial.print("Scale2_Reading: "); Serial.print(scale2.get_units(), 1); Serial.print("g"); Serial.println(); weight2 = scale2.get_units(); Serial.print("Scale3_Reading: "); Serial.print(scale3.get_units(), 1); Serial.print("g"); Serial.println(); weight3 = scale3.get_units(); //Weight1 Serial.println(weight1); if (weight1 < 60) { // do nothing Serial.println("do nothing under 60g"); } else if (weight1 > 90) { // do nothing Serial.println("do nothing over 90g"); } else { // Servo1 if ((weight1 >= 60) && (weight1 <= 90)) { //If the weight1 is 60-90g Serial.println("masu is ON"); // Servo2 for (pos = 170; pos >= 60; pos -= 1) { // goes from 170 degrees to 60 degrees myservo2.write(pos); delay(20); } // I2C Wire.beginTransmission(8) ; // Secondary address is 8 Wire.write("1", strlen("1")); // Send 1 to secondary Wire.endTransmission(); Serial.print("sent "); Serial.println("1"); delay(22000); //mp3 Dozo Dozo Voice Wire.beginTransmission(8) ; // Secondary address is 8 Wire.write("2", strlen("2")); // Send 2 to secondary Wire.endTransmission(); Serial.print("sent "); Serial.println("2"); delay(500); // Servo2 for (pos = 60; pos <= 170; pos += 1) { // goes from 60 degrees to 170 degrees myservo2.write(pos); delay(20); } }//if }//else delay(500); //Weight2 Serial.println(weight2); if (weight2 < 60) { // do nothing Serial.println("do nothing under 60g"); } else if (weight2 > 90) { // do nothing Serial.println("do nothing over 90g"); } else { // Servo1 if ((weight2 >= 60) && (weight2 <= 90)) { //If the weight2 is 60-90g Serial.println("masu is ON"); for (pos = 0; pos <= 90; pos += 1) { myservo1.write(pos); delay(20); } // Servo2 for (pos = 170; pos >= 60; pos -= 1) { // goes from 170 degrees to 60 degrees myservo2.write(pos); delay(20); } // I2C Wire.beginTransmission(8) ; // Secondary address is 8 Wire.write("1", strlen("1")); // Send 1 to secondary Wire.endTransmission(); Serial.print("sent "); Serial.println("1"); delay(22000); //mp3 Dozo Dozo Voice Wire.beginTransmission(8) ; // Secondary address is 8 Wire.write("3", strlen("3")); // Send 3 to secondary Wire.endTransmission(); Serial.print("sent "); Serial.println("3"); delay(500); // Servo2 for (pos = 60; pos <= 170; pos += 1) { // goes from 60 degrees to 170 degrees myservo2.write(pos); delay(20); } // Servo1 for (pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees // in steps of 1 degree myservo1.write(pos); // tell servo1 to go to position in variable 'pos' delay(20); // waits 30ms for the servo to reach the position // } }//if }//else delay(500); //Weight3 Serial.println(weight3); if (weight3 < 60) { // do nothing Serial.println("do nothing under 60g"); } else if (weight3 > 90) { // do nothing Serial.println("do nothing over 90g"); } else { // Servo1 if ((weight3 >= 60) && (weight3 <= 90)) { //If the weight3 is 60-90g Serial.println("masu is ON"); for (pos = 0; pos <= 180; pos += 1) { myservo1.write(pos); delay(20); } // Servo2 for (pos = 170; pos >= 60; pos -= 1) { // goes from 170 degrees to 60 degrees myservo2.write(pos); delay(20); } // I2C Wire.beginTransmission(8) ; // Secondary address is 8 Wire.write("1", strlen("1")); // Send 1 to secondary Wire.endTransmission(); Serial.print("sent "); Serial.println("1"); delay(22000); //mp3 Dozo Dozo Voice Wire.beginTransmission(8) ; // Secondary address is 8 Wire.write("4", strlen("4")); // Send 4 to secondary Wire.endTransmission(); Serial.print("sent "); Serial.println("4"); delay(500); // Servo2 for (pos = 60; pos <= 170; pos += 1) { // goes from 60 degrees to 170 degrees myservo2.write(pos); delay(20); } // Servo1 for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees // in steps of 1 degree myservo1.write(pos); // tell servo1 to go to position in variable 'pos' delay(20); // waits 30ms for the servo to reach the position // } }//if }//else delay(500); } //loop