Created
October 18, 2015 02:33
-
-
Save RyoSaitoOp3/1450c18e5a8e5ad830a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h>; | |
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); | |
float a_in, temp_c, t ; | |
void setup() | |
{ | |
Serial.begin(9600) ; // パソコン(ArduinoIDE)とシリアル通信の準備を行う | |
lcd.begin(16, 2); //16x2のキャラクタディスプレイであると宣言 | |
lcd.clear(); //LCDディスプレイに何か書かれていれば消去し、カーソル位置を左上にする | |
lcd.setCursor(0, 0); //lce.clearで左上になっているはずだが、念のため | |
lcd.print("hello, world!"); | |
lcd.setCursor(5, 1); | |
lcd.print(" C"); //温度表示の"℃"の代わり。°も設定すれば表示できるはずだが、行わなかった。 | |
} | |
void loop() { | |
if(Serial.available()>0){ | |
Serial.read(); | |
} | |
a_in = analogRead(0) ; // アナログ0番ピンからセンサー値を読込む | |
temp_c = (a_in * 0.58388) - 1.42141; | |
char t[6]; // 温度表示の文字列の内容は 0.0 ~ 100.0 の可能性があるため、 | |
// 最低でも 5 文字+文字列終端記号の 1 文字分を確保しておく。 | |
dtostrf( temp_c, 3, 1, t ); // 温度の数値を文字列に変換する。 | |
Serial.println( t ); // 改行しながらシリアルモニタに出力 | |
//温度のLCDモニタへの表示 | |
lcd.setCursor(0, 1); | |
lcd.print(temp_c); | |
delay(100); //100msごとに更新 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment