Skip to content

Commit

Permalink
✨ (spikes): Add lk_led_
Browse files Browse the repository at this point in the history
Create a spike lk_led tthat does not use FastLED but CoreLED instead.
  • Loading branch information
HPezz committed Jan 28, 2022
1 parent c331cf8 commit 7c21597
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_subdirectory(${SPIKES_DIR}/lk_ble)
add_subdirectory(${SPIKES_DIR}/lk_cg_animations)
add_subdirectory(${SPIKES_DIR}/lk_lcd)
add_subdirectory(${SPIKES_DIR}/lk_led)
add_subdirectory(${SPIKES_DIR}/lk_led_)
add_subdirectory(${SPIKES_DIR}/lk_rfid)
add_subdirectory(${SPIKES_DIR}/lk_ticker_timeout)
add_subdirectory(${SPIKES_DIR}/lk_wifi)
Expand Down
21 changes: 21 additions & 0 deletions spikes/lk_led_/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

add_mbed_executable(spike_lk_led_)

target_include_directories(spike_lk_led_
PRIVATE
.
)

target_sources(spike_lk_led_
PRIVATE
main.cpp
)

target_link_libraries(spike_lk_led_
CoreLED
)

target_link_custom_leka_targets(spike_lk_led_)
73 changes: 73 additions & 0 deletions spikes/lk_led_/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include <cstddef>

#include "PinNames.h"

// #include "drivers/BufferedSerial.h"
// #include "drivers/HighResClock.h"
// #include "rtos/Kernel.h"
#include "rtos/ThisThread.h"

#include "CoreLED.h"
#include "CoreSPI.h"
#include "HelloWorld.h"
#include "LogKit.h"

using namespace leka;
using namespace std::chrono;

auto const NUM_BELT_LEDS = 20;
auto const NUM_EAR_LEDS = 2;
auto const BRIGHTNESS = 255;
const std::array<RGB, 6> COLORS = {
RGB::pure_green, RGB::pure_red, RGB::pure_blue, RGB::yellow, RGB::cyan, RGB::magenta,
};

void ChangeColor(CoreLED coreled, uint8_t index)
{
if (index < COLORS.size()) {
coreled.setColor(COLORS[index]);
coreled.showColor();
}
coreled.hideColor();
}

auto main() -> int
{
mbed::SPI spi(LED_BELT_SPI_MOSI, NC, LED_BELT_SPI_SCK);
CoreSPI corespi(spi);
CoreLED belt(corespi, NUM_BELT_LEDS);
CoreLED ear(corespi, NUM_EAR_LEDS);

logger::init();

HelloWorld hello;
hello.start();
log_info("Hello, World!\n\n");

int index = 0;

belt.setColor(COLORS[index]);
ear.setColor(RGB::pure_blue);

belt.showColor();
ear.showColor();

rtos::ThisThread::sleep_for(2s);

while (true) {
index++;

ChangeColor(belt, index);
ChangeColor(ear, index);

if (not belt.isOn() && not ear.isOn()) {
index = 0;
}

rtos::ThisThread::sleep_for(10ms);
}
}

0 comments on commit 7c21597

Please sign in to comment.