Browse Source

Examples: Add main_adc

usb_midi_launchpad
heck 6 months ago
parent
commit
c67e6723cd
  1. 46
      examples/main_adc.cc
  2. 28
      examples/main_adc.hh

46
examples/main_adc.cc

@ -0,0 +1,46 @@
#include "main_adc.hh"
#include "utils.hh"
#include <functional>
namespace Heck {
namespace { // anonymous namespace for internal linkage
ld::DaisySeed seed{};
Observer<int> pot1{};
SWTimer scan_pots{};
void init()
{
seed.Init(Constants::CPU_BOOST480MHZ);
seed.StartLog(Constants::Developer::LOG_BLOCKS_BOOT);
ld::AdcChannelConfig adc_cfg[3];
adc_cfg[0].InitSingle(ld::DaisySeed::GetPin(Constants::Hardware::PIN_POT_1));
seed.adc.Init(adc_cfg, 1);
seed.adc.Start();
scan_pots.set_period(10);
scan_pots.set_callback([]() {
pot1.on_change_fuzzy(seed.adc.Get(0), 10, [](int val) {
seed.PrintLine("POT_1: %d", val);
});
});
}
void mainloop()
{
u32&& time_boot_ms{};
while (true) {
time_boot_ms = ld::System::GetNow();
scan_pots.is_it_already_time_again(time_boot_ms);
}
}
} // namespace
} // namespace Heck
int main()
{
Heck::init();
Heck::mainloop();
}

28
examples/main_adc.hh

@ -0,0 +1,28 @@
#ifndef HECK_MAIN_ADC_HH
#define HECK_MAIN_ADC_HH
#include <functional>
#include "types.hh"
namespace Heck {
namespace Constants {
namespace Hardware {
constexpr int PIN_BUTTON_1 = 28;
constexpr int PIN_POT_1 = 15;
constexpr int PIN_POT_2 = 16;
constexpr int PIN_POT_3 = 15;
}
constexpr bool CPU_BOOST480MHZ = false;
namespace Developer {
constexpr bool LOG_BLOCKS_BOOT = false;
}
} // namespace Constants
//Hardware
extern ld::DaisySeed seed;
// extern ld::Switch but_rec;
} // namespace Heck
#endif
Loading…
Cancel
Save