Possible to do multiple if else/trigger statements on one arduino?
i think know answer this, figured i'd ask in case - can run multiple if else/trigger statements monitoring sensors on 1 arduino?
the first set of code monitoring temperature , turn on power outlet if temp drops level. second set of code monitoring moisture level of soil , turn on power outlet if moisture drops below level.
my guess need use 2 diff arduinos, 1 each code...
this note code way!
can combine code:
but have code running?
the first set of code monitoring temperature , turn on power outlet if temp drops level. second set of code monitoring moisture level of soil , turn on power outlet if moisture drops below level.
my guess need use 2 diff arduinos, 1 each code...
this note code way!
can combine code:
code: [select]
#include <u8glib.h> // u8glib library
#include <dht.h> // dht library
#define dht_apin a5 // analog pin sensor connected
dht dht;
int pinout = 8;
/*uncomment , comment*/
u8glib_sh1106_128x64 u8g(13, 11, 10, 9, 8); // din=13, clk=11, cs=10, dc=9, reset=8
//u8glib_ssd1306_128x32 u8g(13, 11, 10, 9, 8); // din=13, clk=11, cs=10, dc=9, reset=8
//u8glib_ssd1306_128x64 u8g(13, 11, 10, 9, 8); // din=13, clk=11, cs=10, dc=9, reset=8
void draw(void)
{
u8g.setfont(u8g_font_fub17r); // select font
u8g.drawstr(0, 20, "temp: "); // put string of display @ position x, y
u8g.drawstr(0, 60, "hum: ");
u8g.setprintpos(72, 20); // set position
u8g.print((dht.temperature * 9) / 5 + 32, 0); // display temperature dht11 in fahrenheit
u8g.println("f");
u8g.setprintpos(60, 60); // set position
u8g.print(dht.humidity, 0); // display humidity dht11
u8g.println("%");
}
void setup(void)
{
}
void loop(void)
{
dht.read11(dht_apin); // read apin on dht11
u8g.firstpage();
do
{
draw();
} while( u8g.nextpage() );
if (dht.temperature <= 70){
digitalwrite(pinout, high);
}
else {
digitalwrite(pinout, low);
}
delay(2000); // delay of 2 sec before accessing dht11 (min - 2sec)
}
but have code running?
code: [select]
const int val_probe = 0; //analog pin 0
const int moisture_level = 250; // value after led goes on
void setup()
{
serial.begin(9600);
pinmode(13, output);
pinmode(7, output);
}
void ledstate(int state)
{
digitalwrite(13,state);
}
void loop()
{
int moisture = analogread(val_probe);
serial.print("moisture = ");
serial.println(moisture);
if(moisture > moisture_level)
{
ledstate(high);
digitalwrite(7,high);
}
else
{
ledstate(low);
digitalwrite(7,low);
}
delay(500);
}
if put 2 pieces of code should work. it'll run through code normal checking 1 after other. start @ top of loop , work way through; it'll @ 1 if/else tree , process of information , check conditions, , it'll go on next if/else tree , same thing.
one arduino can have infinite amount of if/else statements in it checking. long have enough input , output pins on arduino take in whatever data need , output whatever data need, should alright.
one arduino can have infinite amount of if/else statements in it checking. long have enough input , output pins on arduino take in whatever data need , output whatever data need, should alright.
Arduino Forum > Using Arduino > Project Guidance > Possible to do multiple if else/trigger statements on one arduino?
arduino
Comments
Post a Comment