
Eftersom ni är sådana snillen på det här och detta är första gången jag ens rör en Arduino så skulle jag tacksamt ta emot tips och råd
om ni ser något som är rent fel, eller kanske bara kan förbättras.
Kod: Markera allt
unsigned long up_time;
unsigned long down_time;
const int upin = 7; // height sensor low input
const int upout = 13; // compressor
const int downin = 5; // height sensor high input
const int downout = 9; // relief valve
int upState = 0; // variable for reading height sensor status
int downState = 0;
void setup() {
// initialize pin output:
pinMode(upout, OUTPUT);
pinMode(downout, OUTPUT);
// initialize pin input:
pinMode(upin, INPUT);
pinMode(downin, INPUT);
delay(10000); // startup delay
digitalWrite(upout, HIGH); // start compressor
delay(5000); // wait 5 sec
digitalWrite(upout, LOW); // stop compressor
}
void loop() {
upState = digitalRead(upin);
if (upState == LOW ) up_time = millis();
if ((millis() - up_time) >= 15000)
{
// start compressor
digitalWrite(upout, HIGH);
}
else {
// stop compressor
digitalWrite(upout, LOW);
}
{
downState = digitalRead(downin);
if (downState == LOW ) down_time = millis();
if ((millis() - down_time) >= 15000)
{
// activate relief valve
digitalWrite(downout, HIGH);
}
else {
// deactivate relief valve
digitalWrite(downout, LOW);
}
}
}