EditToHeaderToFooter

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
#include <OneWire.h>
#include <DallasTemperature.h>
 
const int pHeat = 12; //Digital
OneWire oneWire(2);
DallasTemperature sensor(&oneWire);
 
void setup() {
  Serial.begin(9600);
  Serial.println("Begin OneWireTemprature");
  sensor.begin();
  delay(100);
  
  Serial.print("  sensor.getDeviceCount ==> ");
  Serial.println(sensor.getDeviceCount());
  delay(100);
}
 
float gCurrent = 0;
float gTarget = 70;
float gFullPowere = gTarget - 10;
 
int gFreq = 1000;
void loop() {
  sensor.requestTemperatures();
  float vMesure = sensor.getTempCByIndex(0);
 
  if (0 < vMesure && vMesure < 110) {
    gCurrent = vMesure; // 異常値ガード
  }
 
  if (gTarget < gCurrent) {
    Serial.print(gTarget );
    Serial.print(",");
    Serial.print(gCurrent);
    Serial.print(",");
    Serial.print(0);
    Serial.println("");
    digitalWrite(pHeat, LOW);
    delay(gFreq);
  }
  else if (gCurrent < gFullPowere) {
    Serial.print(gTarget );
    Serial.print(",");
    Serial.print(gCurrent);
    Serial.print(",");
    Serial.print(100);
    Serial.println("");
    digitalWrite(pHeat, HIGH);
    delay(gFreq);
  }
  else {
    float vDiff = gTarget - gCurrent;
    float vDuty = vDiff / 10;
    float vTimeHigh = vDuty * gFreq;
    float vTimeLow = gFreq - vTimeHigh;
    Serial.print(gTarget );
    Serial.print(",");
    Serial.print(gCurrent);
    Serial.print(",");
    Serial.print(vDuty * 100);
    Serial.println("");
    digitalWrite(pHeat, HIGH);
    delay(vTimeHigh);
    digitalWrite(pHeat, LOW);
    delay(vTimeLow);
  }
}
リロード   新規 編集 凍結 差分 添付 複製 改名   技術 一覧 検索 最新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2017.0911 (月) 2248.2000 (460d)