libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
encoder.h
Go to the documentation of this file.
1#pragma once
2#ifndef DSY_ENCODER_H
3#define DSY_ENCODER_H
4#include "daisy_core.h"
5#include "per/gpio.h"
6#include "hid/switch.h"
7
8namespace daisy
9{
18{
19 public:
22
26 void Init(Pin a, Pin b, Pin click, float update_rate = 0.f);
30 void Debounce();
31
33 inline int32_t Increment() const { return updated_ ? inc_ : 0; }
34
36 inline bool RisingEdge() const { return sw_.RisingEdge(); }
37
39 inline bool FallingEdge() const { return sw_.FallingEdge(); }
40
42 inline bool Pressed() const { return sw_.Pressed(); }
43
45 inline float TimeHeldMs() const { return sw_.TimeHeldMs(); }
46
50 inline void SetUpdateRate(float update_rate) {}
51
52 private:
53 uint32_t last_update_;
54 bool updated_;
55 Switch sw_;
56 GPIO hw_a_, hw_b_;
57 uint8_t a_, b_;
58 int32_t inc_;
59};
60} // namespace daisy
61#endif
Generic Class for handling Quadrature Encoders Inspired/influenced by Mutable Instruments (pichenet...
Definition encoder.h:18
void Init(Pin a, Pin b, Pin click, float update_rate=0.f)
float TimeHeldMs() const
Definition encoder.h:45
bool Pressed() const
Definition encoder.h:42
Encoder()
Definition encoder.h:20
void SetUpdateRate(float update_rate)
Definition encoder.h:50
~Encoder()
Definition encoder.h:21
bool FallingEdge() const
Definition encoder.h:39
bool RisingEdge() const
Definition encoder.h:36
int32_t Increment() const
Definition encoder.h:33
General Purpose I/O control.
Definition gpio.h:22
Definition leddriver.h:33
Definition switch.h:18
float TimeHeldMs() const
Definition switch.h:84
bool RisingEdge() const
Definition switch.h:65
bool Pressed() const
Definition switch.h:74
bool FallingEdge() const
Definition switch.h:68
Hardware defines and helpers for daisy field platform.
Definition index.h:2
representation of hardware port/pin combination
Definition daisy_core.h:193