One button toggles the temperature measurements on/off and the other but-ton toggles the brightness measurements on/off. When a sensor is turned off (disabled) then the system is in maintenance operation mode. A disa-bled sensor should not trigger the alarm. Only when the two sensors are enabled then the system is normal operating.
const int BUTTON1 = 8;
const int BUTTON2 = 9;
const int LDR_IN = A2;
const int NTC_IN = A1;
Void setup() {
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
}
void loop() {
int button_state;
button_state = digitalRead(BUTTON1);
if (button_state == ) {
digitalWrite();
}
else {
digitalWrite(;
}
}
I started this, but i am not sure what command i should use in order to turn on/off one sensor. I will be very thankful if someone could help me.
Your code cannot compile.
It is impossible to tell what you are trying to write to.
WhatAbeast:
One button toggles the temperature measurements on/off
You will need a variable to keep track of if temperature measurement is ON or OFF. There is a type of variable called "boolean" that will hold a value that is 'true' (1) or 'false' (0).
boolean TemperatureOn = false;
Then you should look at:
File->Examples->02.Digital->StateChangeDetection
File->Examples->02.Digital->Button
File->Examples->02.Digital->Debounce
Those three examples will give you some sense of how to read a button, figure out if the button was just pushed, and prevent mechanical bounces from counting a single press more than once. Once you detect that a button has been pressed:
TemperatureOn = !TemperatureOn;
That flips the boolean variable from true to false or false to true.
Then you can use "if (TemperatureOn)" to execute the part of your code that only gets done when the temperature reading is turned on.
Start by giving your buttons distinct names. 5 days from now you won't reme2if button1 is the temperature button.
Instead of turning the sensor off, think more like ignoring its value.
Here is an example program I wrote which is many thousands of lines long. But the main loop is very simple...
void loop() {
readSensors();
readButtons();
doCalculations();
setOutputs();
}
Obviously the calculations and output depend on what buttons are currently pressed and what buttons were pressed in the past.