/* ** Example Arduino sketch for SainSmart I2C LCD2004 adapter for HD44780 LCD screens ** Readily found on eBay or http://www.sainsmart.com/ ** The LCD2004 module appears to be identical to one marketed by YwRobot ** ** Address pins 0,1 & 2 are all permenantly tied high so the address is fixed at 0x27 ** ** Written for and tested with Arduino 1.0 ** This example uses F Malpartida's NewLiquidCrystal library. Obtain from: ** https://bitbucket.org/fmalpartida/new-liquidcrystal ** ** Edward Comer ** LICENSE: GNU General Public License, version 3 (GPL-3.0) ** ** NOTE: TEsted on Arduino NANO whose I2C pins are A4==SDA, A5==SCL */ #include <Wire.h> #include <LCD.h> #include <LiquidCrystal_I2C.h> #define I2C_ADDR 0x3F // Define I2C Address where the PCF8574A is #define BACKLIGHT_PIN 3 #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 int n = 1; int threshold0=200; int threshold1=400; int ledPin = 13; int ledState= HIGH; LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); void setup() { Serial.begin(9600); lcd.begin (20,4); pinMode(ledPin, OUTPUT); // Switch on the backlight lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(10 ); lcd.home (); // go home lcd.write(Serial.read()); lcd.setCursor(0,0); lcd.println("SPHS Engineering/Hort"); //lcd.scrollDisplayLeft(); lcd.setCursor ( 0, 1 ); // go to the 2nd line lcd.print("Test BY: MATT/TYLER"); lcd.setCursor ( 0, 2 ); // go to the third line lcd.print("Moisture Sensor"); lcd.setCursor ( 0, 3 ); // go to the fourth line lcd.print("Soil Cond.:"); } void loop() { lcd.setCursor (11,3); int range = map(analogRead(0), threshold0, threshold1, 0, 2); switch (range) { case 0: // your hand is on the sensor lcd.print("PERM.WILT"); digitalWrite(ledPin, HIGH); break; case 1: // your hand is close to the sensor lcd.print("FIELD CAP."); digitalWrite(ledPin, LOW); break; case 2: // your hand is a few inches from the sensor lcd.print("SATURATED "); digitalWrite(ledPin, LOW); break; //digitalWrite(ledPin, HIGH); } // if (ledState == LOW) //analogRead // else // ledState = LOW; // set the LED with the ledState of the variable: delay(50); // delay in between reads for stability } // constants won't change. Used here to // set pin numbers: // the number of the LED pin // Variables will change: // ledState used to set the LED // the follow variables is a long because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. // set the digital pin as output: //void loop() /* if (analogRead(0)>threshold0) {lcd.print("dry"); } else if(threshold0<analogRead(0)<threshold1); {lcd.print("moist");} else else if(analogRead(0)>threshold1); {lcd.print("soaked");} } */ // Backlight on/off every 3 seconds /* lcd.setCursor (14,3); // go col 14 of line 3 lcd.print(analogRead(0)>200); lcd.print(analogRead(0)<400);}*/ // when characters arrive over the serial port... //if (Serial.available()) // wait a bit for the entire message to arrive // delay(100); // clear the screen //lcd.clear(); // read all the available characters //while (Serial.available() > 0) // Serial.print(); // Serial.print(analogRead(0));
Friday, February 6, 2015
Arduino Code
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment