From 7adea8d39c6d8126339efb60b626125df4cae444 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 5 Jul 2023 21:32:43 +0200 Subject: [PATCH] BYTEBEAT BYTEBEAT BYTEBEAT \o/ \o/ \o/ http://countercomplex.blogspot.com/2011/10/algorithmic-symphonies-from-one-line-of.html --- Core/Src/cppmain.cc | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/Core/Src/cppmain.cc b/Core/Src/cppmain.cc index 868838e..39795ac 100644 --- a/Core/Src/cppmain.cc +++ b/Core/Src/cppmain.cc @@ -8,9 +8,11 @@ #include "cppmain.h" #include "main.h" #include "usbd_cdc_if.h" +#include "dac.h" #include #include #include +#include "limits" const double pi{ std::acos(-1) }; @@ -26,22 +28,25 @@ void log(std::string &&msg) log(msg); } -std::function printheck = [] { log("heck"); }; +void set_dac_1(uint32_t val) +{ + HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_L, val); +} + +void set_dac_2(uint32_t val) +{ + HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_L, val); +} void cppmain(void) { - log(pi); - long i{ 0 }; + HAL_DAC_Start(&hdac, DAC_CHANNEL_1); + long t{ 0 }; while (true) { - const float piwrap{ std::fmod(float(i / 100.), float(2. * pi)) }; - const float sin_factor = std::abs(float(sin(piwrap))); - - HAL_Delay(static_cast(sin_factor * 100.0)); - - HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin); - log({ "hello heck:" + std::to_string(i) + " piwrap:" + std::to_string(piwrap) + - " fact:" + std::to_string(sin_factor) }); - printheck(); - i++; + unsigned char res = t * ((t >> 12 | t >> 8) & 63 & t >> 4); + set_dac_1((res % 256) * 100); + for (int g = 0; g < 6000; g++) {} + t++; + t %= (std::numeric_limits::max() - 1); } }