Skip to content
Snippets Groups Projects
Commit a40ea098 authored by Xoaquin Castrelo's avatar Xoaquin Castrelo
Browse files

Added support for buttons.

parent 1fdf3f18
Branches
No related tags found
No related merge requests found
#include "buttons.hpp"
#include "uart.hpp"
#include "time.hpp"
#include <avr/io.h>
static bool lastStateA = false;
static bool lastStateB = false;
static uint32_t lastMillisA = 0;
static uint32_t lastMillisB = 0;
void initButtons()
{
DDRC &= ~(1 << DDC5) & ~(1 << DDC4); // set PC5 and PC4 as inputs
PORTC |= (1 << PORTC5) | (1 << PORTC4); // enable pullups
}
void updateButtons()
{
uint32_t currMillis = getCurrentMillis();
bool currStateA = (PINC & (1 << PINC5));
bool currStateB = (PINC & (1 << PINC4));
if (currStateA != lastStateA)
{
lastStateA = currStateA;
if (!currStateA && (currMillis - lastMillisA) > 50)
writeUart('a');
lastMillisA = currMillis;
}
if (currStateB != lastStateB)
{
lastStateB = currStateB;
if (!currStateB && (currMillis - lastMillisB) > 50)
writeUart('b');
lastMillisB = currMillis;
}
}
#ifndef BUTTONS_H
#define BUTTONS_H
/**
* Initialises the button logic.
*/
void initButtons();
/**
* Updates the button logic.
* Should be called periodically.
*/
void updateButtons();
#endif /* BUTTONS_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment