int measurePin = 0;
int ledPower = 7;
int samplingTime = 280; // parametry pomiarowe
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
float dust; // zmienna pojedyńczego pomiaru
float MIN_VOLTAGE = 600.0;
int MAX_ITERS = 10;
float avgDust = 0; // uśredniony wynik z 10 pomiarów
int iter = 0;
//arduino
void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT);
}
float measureDust() {
digitalWrite(ledPower,LOW); // włączenie LED
delayMicroseconds(samplingTime);
voMeasured = analogRead(measurePin); // odczytanie wartości zmierzonej
delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH); // wyłączenie LED
delayMicroseconds(sleepTime);
calcVoltage = (5000.0 / 1024.0) * voMeasured;
//dustDensity = 0.17 * calcVoltage - 0.1;
if (calcVoltage > MIN_VOLTAGE)
{
return (calcVoltage - MIN_VOLTAGE) * 0.2;
//return (0.17 * calcVoltage) - 0.1; różne opcje zamiany tego na wartość
}
return 0;
}
//arduino
void loop(){
avgDust = 0;
iter = 0;
while (iter < MAX_ITERS)
{
dust = measureDust(); //funkcja zwracająca pojedyńczy pomiar pyłu
if (dust > 0)
{
avgDust += dust;
iter++;
delay(10);
}
}
avgDust /= MAX_ITERS;
//avgDust = measureDust();
Serial.print("D = ");
Serial.print(avgDust);
Serial.println("ug/m3");
delay(2000);
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}