Created
October 15, 2014 10:45
-
-
Save hhc0null/f8dd1e87a2e4f6151ecb to your computer and use it in GitHub Desktop.
un_code.c
This file contains hidden or 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
/* | |
デフォルトで26.85に設定している. | |
_is_thermistor_adc_readyは1秒おきにtrueになる.(1秒おきに温度を取得して表示) | |
それ以外の間はずっと前回取得した値を表示する. | |
--- | |
なぜか、26.85が表示されて、現在の値が表示されて、26.85が表示されて、現在の値が表示されて。。。という繰り返し | |
*/ | |
void ControlRoutine(void) | |
{ | |
static int tempature; | |
static int now_tempature[4] = {5, 8, 6, 2}; // this is 300 [Kelvin]. | |
static int dotpos = 2; | |
if(_is_thermistor_adc_ready) { | |
int thermistor_value = ThermistorADConv(); | |
// サーミスタの値を温度に直すための計算.kではじまるのはすべて定数. | |
double t = 1/(log(kProtectionResistance*thermistor_value/(1023.0-thermistor_value)/kBaseResistance)/kBValue+1/kBaseTempature)+kAbsoluteZero; | |
// (0,100]の範囲に温度があるか? | |
bool is_not_within = 0 > (int)t || (int)t >= 100; | |
if(is_not_within) { | |
t = 88.88; // 8888ってエラーっぽいでしょ | |
} | |
// 7セグのdpの位置を指定.-1は全点灯. | |
dotpos = is_not_within? -1: 2; | |
// 表示するために小数点二桁に整形 26.85234 -> 26.85 | |
tempature = (int)Myround(t); | |
// 表示するための配列に格納 | |
for(int i = 0, x = 1; i < 4; i++) { | |
now_tempature[i] = (tempature/x)%10; | |
x *= 10; | |
} | |
} | |
// dpと表示するための配列を渡せばオッケーなインターフェース | |
DisplayValues(dotpos, now_tempature); | |
// ON/OFF制御.関係ない. | |
HeaterControl(tempature); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment