Button - INPUT_PULLUP
hi,
i've read somewhere can skip using pullup resistors (or rather use internal ones instead) buttons if use input_pullup constant during pinmode setup - correct? tried it, results in arduino thinking buttons pressed time (may soldering problem, i'd ensure it's not else first).
this code:
is correct?
i've read somewhere can skip using pullup resistors (or rather use internal ones instead) buttons if use input_pullup constant during pinmode setup - correct? tried it, results in arduino thinking buttons pressed time (may soldering problem, i'd ensure it's not else first).
this code:
code: [select]
#include <wire.h>
#include <bh1750.h>
#include <liquidcrystal_i2c.h>
liquidcrystal_i2c lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, positive);
bh1750 czujnik_swiatla; //0x23
uint16_t luksy;
int stan_wgore = 0, stan_wdol = 0, stan_onoff = 0;
void clearline(boolean firstline)
{
if(firstline == false)
lcd.setcursor(0, 1);
else
lcd.setcursor(0, 0);
for(int = 0; < 16; ++i)
lcd.write(' ');
}
void setup()
{
lcd.begin(16, 2);
lcd.backlight();
lcd.setcursor(0, 0);
czujnik_swiatla.begin();
pinmode(12, input_pullup);
pinmode(13, input_pullup);
pinmode(7, input_pullup);
}
void loop()
{
clearline(true);
lcd.setcursor(0, 0);
stan_wgore = digitalread(12);
stan_wdol = digitalread(13);
if(stan_wgore == high)
lcd.print("12");
else if(stan_wdol == high)
lcd.print("13");
stan_onoff = digitalread(7);
clearline(false);
if(stan_onoff == high)
{
luksy = czujnik_swiatla.readlightlevel();
lcd.setcursor(0, 1);
lcd.print(luksy);
}
}
is correct?
if use pull-up resistors button connect between pin , ground , read low when pressed , high when not pressed.
Arduino Forum > Using Arduino > Programming Questions > Button - INPUT_PULLUP
arduino
Comments
Post a Comment