私は ATmega8 を使った小さなプロジェクトの真っ最中です。DS18B20 センサーから温度を読み取り、rf433 トランスミッターを使用して結果を送信したいと考えています。すべて問題ありませんが、ソースのサイズ... ATmega には 7,168 バイトのメモリしかありませんが、バイナリは 8,310 バイトです。不要なものを削除しましたが、それでも多すぎます。サイズを小さくするのを手伝ってもらえますか?私はArduino IDEを使ってコードを書いていますが、おそらく純粋なCではもっと軽いでしょうか?
どんな助けでも感謝します:)
コード:
// RF433
#include <VirtualWire.h>
// Dallas
#include <DallasTemperature.h>
#include <OneWire.h>
//const char *message; // Our message to send
const int ONE_WIRE_BUS = 2; //DS18S20 Signal pin on digital 2
//Temperature chip i/o
OneWire oneWire(ONE_WIRE_BUS); // on digital pin 2
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature Sensors(&oneWire);
void setup() {
// RF433
vw_set_ptt_inverted(true);
vw_setup(2000);
Sensors.begin();
}
void loop() {
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Sensors.requestTemperatures(); // Send the command to get temperatures
float dTmp = Sensors.getTempCByIndex(0);
// Why "byIndex"?
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
char buf[6];
dtostrf(dTmp, 6, 3, buf);
char Msg[9];
strcpy(Msg, "TP:");
strncat(Msg, buf, 6);
// Send temp.
for (int i = 0; i < 10; ++i) // avoid loosing packets
{
vw_send((uint8_t *)Msg, strlen(Msg));
vw_wait_tx();
delay(300);
}
// Sleep 1 min.
delay(60000);
}