class Hall{
private:
int led_pin, btn_pin;
public:
Hall(int led_pin, int btn_pin){
DDRD |= (1<<led_pin);//pinMode(led_pin, OUTPUT); Seta 1 em DDRD_BIT3 (saída)
PORTD &= ~(1<<led_pin); //digitalWrite(led_pin,LOW); Seta 0 em PD3 (led off)
DDRD &= ~(1<<btn_pin );//pinMode(btn_pin,INPUT_(...)) Seta 0 em DDRD_BIT2 (entrada)
PORTD |= (1<<btn_pin);//INPUT_PULLUP Seta 1 em PD2 (habilita pullup)
this->led_pin = led_pin;
this->btn_pin = btn_pin;
}
void led_set(int s){
(s==0)? (PORTD &= ~(1<<this->led_pin)):(PORTD |= (1<<this->led_pin));///if ternário
}
void led_invert(){
PORTD ^= (1<<this->led_pin);//Inverter o estado do led
}
void ms(int ms){
_delay_ms(ms);
}
};
void setup() {
Hall hall(3,2);
for (;;){
hall.led_invert();
hall.ms(500);
//hall.led_set(0);
//hall.ms(500);
}
}
void loop() {
// put your main code here, to run repeatedly:
}