Commit c2294f9c authored by Martin Vítek's avatar Martin Vítek
Browse files

Encoder is working

One step consist of 4 pulses... Why?
parent 02fd84da
......@@ -85,4 +85,22 @@ void SafeSolderingStation::wellcome()
_delay_ms(750);
lcd.clear();
}
\ No newline at end of file
}
void SafeSolderingStation::test_encoder()
{
if (enc.event)
{
lcd.clear();
lcd.gotoxy_new(0,0);
lcd.write_num(enc.count);
lcd.gotoxy_new(1,0);
if(enc.get_button()) lcd.write_text("Pressed");
else lcd.write_text("Released");
enc.event = false;
}
}
......@@ -29,6 +29,8 @@ class SafeSolderingStation
void init();
void wellcome();
void test_encoder();
};
//Global instance
......
......@@ -24,12 +24,15 @@ class encoder
volatile bool button;
public:
volatile bool event;
volatile uint8_t count;
encoder(encoder_config &config)
{
}
encoder()
encoder(): event(false), count(0)
{
//Inputs
PORTA.DIRCLR = PIN2_bm;
......@@ -43,25 +46,53 @@ class encoder
//Enable IRQs at low priority
PORTA.INTCTRL = PORT_INT0LVL_LO_gc;
PORTA.INT0MASK = PIN2_bm;
PORTB.INTCTRL = PORT_INT0LVL_LO_gc;
PORTB.INT0MASK = PIN2_bm | PIN3_bm;
PORTB.INTCTRL = PORT_INT0LVL_LO_gc | PORT_INT1LVL_LO_gc;
PORTB.INT0MASK = PIN2_bm;
PORTB.INT1MASK = PIN3_bm;
}
bool get_button() { return button; }
void Ahandler()
void A_handler()
{
if (PORTB.IN & PIN2_bm)
{
if (PORTB.IN & PIN3_bm) count--;
else count++;
}
else
{
if (PORTB.IN & PIN3_bm) count++;
else count--;
}
event = true;
}
void B_handler()
{
if (PORTB.IN & PIN3_bm)
{
if (PORTB.IN & PIN2_bm) count++;
else count--;
}
else
{
if (PORTB.IN & PIN2_bm) count--;
else count++;
}
event = true;
}
void button_handler()
{
if (PORTA.IN & PIN2_bm) button = true;
else button = false;
event = true;
};
};
......@@ -2,22 +2,24 @@
#include <avr/interrupt.h>
#include "encoder.h"
#include "SafeSolderingStation.h"
//Encoder
//Encoder button
ISR(PORTA_INT0_vect)
{
sss.enc.button_handler();
}
//Encoder A
ISR(PORTB_INT0_vect)
{
sss.enc.A_handler();
}
//Encoder B
ISR(PORTB_INT1_vect)
{
sss.enc.B_handler();
}
......
......@@ -13,12 +13,6 @@ int main()
for(;;)
{
/*
led.toggle();
_delay_ms(500);
led.toggle();
_delay_ms(500);
*/
sss.test_encoder();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment