|
一下是我的程序
#include <Wire.h>
#include "pitches.h"
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int qiti;//qiti sensor
int turang;//turang sensor
int guangqiang;
char val;
char m;
Servo servo;
===================================
void setup()
{guangqiang=0;
Serial.begin(9600);
pinMode(4,OUTPUT);
pinMode( 13 , OUTPUT);
servo.attach(9);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.clear(); // 清除LCD畫面
lcd.setCursor(4, 0); //設定顯示開始位置
lcd.print("SET Mode"); //顯示內容
lcd.setCursor(1, 1); //設定顯示開始位置
lcd.print("=*KEYES-HOME*="); //顯示內容
}
===========================================
void lanya(){
val=Serial.read();
if(val=='r')
{
digitalWrite(13,HIGH);
delay((500));
digitalWrite(13,LOW);
delay(500);
Serial.println("keyes");
}
}
=========================================
void lianwang(){
lcd.clear();
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
if(( ( guangqiang) <= ( 800) ))
{
digitalWrite(13 , HIGH );
}
else
{
digitalWrite( 13 , LOW );
}
lcd.print("Moisture :");
lcd.setCursor(0, 1) ;
lcd.print(analogRead(0));
lcd.setCursor(0, 0) ;
int qitisensor=analogRead(2);
qiti=qitisensor;
int turangsensor=analogRead(0);
turang=turangsensor;
Serial.print("t1:");
Serial.print(qiti);
Serial.print(";t2:");
Serial.println(turang);
if (( ( turang ) <= ( 300)))
{
servo.write( 90);
}
else{servo.write(0);}
if (( ( qiti ) >= ( 111)))
{
digitalWrite(4 , HIGH );
}
else
{
digitalWrite(4, LOW );
}
delay(1000);
}
=================================================
void loop()
{ lcd.setCursor(4, 0);
lcd.print("SET Mode");
lcd.setCursor(1, 1); // set LCD word position
lcd.print("= KEYES team =");
if (Serial.available() )
{
delay(100);
switch(Serial.read())
{
case '1': //第一個字元是1的話進入
lanya();
break;
case '2': //第一個字元是2的話進入
lianwang();
break;
}
}
}
我想把子程序lianwang的程序进行循环 怎么做呢
|
|