本帖最后由 数字 于 2015-2-2 14:27 编辑
这是我上传乐联网用的一段代码.
#include <LiquidCrystal.h>
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
Serial.begin(9600);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("MQ135");
pinMode(ledPin, OUTPUT);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
Serial.print("M:");
Serial.println(sensorValue);
lcd.clear();
lcd.print("MQ135");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(sensorValue);
delay(1000);
} |