Skip to content

Instantly share code, notes, and snippets.

@RyoSaitoOp3
Created October 18, 2015 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyoSaitoOp3/1450c18e5a8e5ad830a0 to your computer and use it in GitHub Desktop.
Save RyoSaitoOp3/1450c18e5a8e5ad830a0 to your computer and use it in GitHub Desktop.
#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