//972020 #include #include // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int sensorValue1 = 0; int sensorValue2 = 0; int sensorValue3 = 0; int sensorValue4 = 0; int outputValue1 = 0; int outputValue2 = 0; int outputValue3 = 0; int outputValue4 = 0; int pos = 0; Servo servo1; void setup() { Serial.begin(9600); pinMode(A0, INPUT); // Sensor 1 pinMode(A1, INPUT); // Sensor 2 pinMode(A2, INPUT); // Sensor 3 pinMode(A3, INPUT); // Sensor 4 pinMode(8, OUTPUT); // set up the LCD's number of columns and rows: lcd.begin(0, 2); // Print a message to the LCD. lcd.print("S1: S2: S3: S4:"); //configure pin2 as an input and enable the internal pull-up resistor pinMode(7, INPUT_PULLUP); servo1.attach(10); } void loop() { // read the analog in value: sensorValue1 = analogRead(A0); sensorValue2 = analogRead(A1); sensorValue3 = analogRead(A2); sensorValue4 = analogRead(A3); // map it to the range of the analog out: outputValue1 = map(sensorValue1, 0, 1023, 0, 255); outputValue2 = map(sensorValue2, 0, 1023, 0, 255); outputValue3 = map(sensorValue3, 0, 1023, 0, 255); outputValue4 = map(sensorValue4, 0, 1023, 0, 255); // change the analog out value: analogWrite(8, outputValue1); analogWrite(9, outputValue2); analogWrite(6, outputValue3); analogWrite(13, outputValue4); // print the results to the serial monitor: // Serial.print("sensor = "); // Serial.print(sensorValue1); // Serial.print("\t output = "); // Serial.println(outputValue1); // wait 2 milliseconds before the next loop for the // analog-to-digital converter to settle after the // last reading: delay(2); // Wait for 2 millisecond(s) // Low: 0 - 402 // Medio: 403 - 510 // High: mayor o igual 511 ///////////SENSOR 1///////////// if (sensorValue1>=0 && sensorValue1<=402) { lcd.setCursor(0, 1); lcd.print("L"); } if (sensorValue1>=403 && sensorValue1<=510) { lcd.setCursor(0, 1); lcd.print("M"); } if (sensorValue1>=511) { lcd.setCursor(0, 1); lcd.print("H"); } ///////////SENSOR 2///////////// if (sensorValue2>=0 && sensorValue2<=402) { lcd.setCursor(4, 1); lcd.print("L"); } if (sensorValue2>=403 && sensorValue2<=510) { lcd.setCursor(4, 1); lcd.print("M"); } if (sensorValue2>=511) { lcd.setCursor(4, 1); lcd.print("H"); } ///////////SENSOR 3///////////// if (sensorValue3>=0 && sensorValue3<=402) { lcd.setCursor(8, 1); lcd.print("L"); } if (sensorValue3>=403 && sensorValue3<=510) { lcd.setCursor(8, 1); lcd.print("M"); } if (sensorValue3>=511) { lcd.setCursor(8, 1); lcd.print("H"); } ///////////SENSOR 4///////////// if (sensorValue4>=0 && sensorValue4<=402) { lcd.setCursor(12, 1); lcd.print("L"); } if (sensorValue4>=403 && sensorValue4<=510) { lcd.setCursor(12, 1); lcd.print("M"); } if (sensorValue4>=511) { lcd.setCursor(12, 1); lcd.print("H"); } // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): //// lcd.setCursor(0, 1); // print the number of seconds since reset: /// lcd.print(sensorValue); // lcd.setCursor(6, 1); // lcd.print(outputValue); //read the pushbutton value into a variable int motor1 = digitalRead(7); //print out the value of the pushbutton // Serial.println(sensorVal); // Keep in mind the pullup means the pushbutton's // logic is inverted. It goes HIGH when it's open, // and LOW when it's pressed. Turn on pin 13 when the // button's pressed, and off when it's not: servo1.write(0); if (motor1 == LOW) { //digitalWrite(13, LOW); servo1.write(180); } }