iLMS知識社群(Sites)師生部落格(Blogs)朝陽首頁(Homepage)TronClass教學平台Login
Position: 曹晉翊 > 物聯網
物聯網作業
by 曹晉翊 2017-11-14 21:38:50, Reply(0), Views(225)
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SoftwareSerial.h>// 讀取光敏電阻讀值並列印到 Serial Port
int photocellPin = 2; // 光敏電阻 (photocell) 接在 analog pin 2 上
int photocellVal = 0; // 光敏電阻讀值變數
SoftwareSerial mySerial(0,1);
int i;

void setup() {
  // 開啟 Serial Port,通訊速率為 9600bps (Bits Per Second)
  Serial.begin(9600);
}
void loop() {
  // 讀取光敏電阻並輸出到 Serial Port
  photocellVal = analogRead(photocellPin); 
  
  Serial.println(photocellVal); 
  i=analogRead(photocellPin);
  Serial.println(i); 
 
  Serial.write(i);
     delay(1000);    
}
-------------------------------------------
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
SoftwareSerial mySerial(0, 1); // RX, TX
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {
mySerial.write(1);
if (mySerial.available()>0)
{
  char aa[3];
  for (int i=0;i<3;i++){
      char a=mySerial.read();
  aa[i]=a;
  Serial.println(a);
  delay(1000);
  }
//  Serial.print(aa);
  lcd.begin(16, 2);
  lcd.print(aa);
}
}
Reply