SBK_BarDrive Library 2.2.0
LED bar meter control and queued animations for Arduino
Loading...
Searching...
No Matches
presetTypeDemo.ino
Go to the documentation of this file.
1/**
2 * @file presetTypeDemo.ino
3 * @brief Demonstrates using SBK_BarDrive with a preset MatrixPreset mapping.
4 *
5 * Requirements:
6 * - Supported driver with complatible library (SBK_MAX72xx or SBK_HT16K33 libraries)
7 * - Bar meter display or leds array wired to driver
8 *
9 * @author
10 * Samuel Barabé (Smart Builds & Kits)
11 *
12 * @version 2.2.0
13 * @license MIT
14 */
15
16#include <Arduino.h>
17
18// ──────────────────────────────────────────────
19// SBK BarDrive Configuration Flags
20// ──────────────────────────────────────────────
21#define SBK_BARDRIVE_WITH_ANIM // Give access to preset animations and controls.
22
23// ──────────────────────────────────────────────
24// SBK BarDrive MatrixPreset info
25// ──────────────────────────────────────────────
26/**
27 * More preset could be add upon time or on request.
28 * Preset MatrixPreset values currently available:
29 * - SBK_BarMeter_SK28 : Alias for **SBK BarMeter SK28** PCB using the BL28_3005SK preset.
30 * - SBK_BarMeter_SA28 : Alias for **SBK BarMeter SA28** PCB using the BL28_3005SA preset.
31 * - BL28_3005SK : Native mapping for BL28-3005SK bar meter (7×4 layout, common cathode).
32 * - BL28_3005SA : Native mapping for BL28-3005SA bar meter (4×7 layout, common anode).
33 */
34
35
36// ──────────────────────────────────────────────
37// SELECT YOUR DRIVER SETUP
38// Uncomment one of the following driver configurations
39// ──────────────────────────────────────────────
40
41/* === [A] Using MAX7219/MAX7221 via SOFTWARE SPI (any 3 digital pins) === */
42// #define DIN_PIN A4 ///< Define software SPI Data In pin
43// #define CLK_PIN A5 ///< Define software SPI Clock pin
44// #define CS_PIN A3 ///< Define SPI Chip Select pin
45// #include <SBK_MAX72xxSoft.h>
46// SBK_MAX72xxSoft driver(DIN_PIN, CLK_PIN, CS_PIN, 1); ///< Construct MAX72xx software SPI driver instance for 1 device : (DataIn pin, Clock pin, Chip Select pin, devices number)
47// #include <SBK_BarDrive.h>
48// SBK_BarDrive<SBK_MAX72xxSoft> bar(&driver, 0, MatrixPreset::BL28_3005SK); ///< Construct using matrix type bar meter preset (auto-mapped layout) : (driver, device index, MatrixPreset type)
49
50/* === [B] Using MAX7219/MAX7221 via HARDWARE SPI (dedicated MCU SPI pins) === */
51// #define CS_PIN A3 ///< Define SPI Chip Select pin
52// #include <SBK_MAX72xxHard.h>
53// SBK_MAX72xxHard driver(CS_PIN, 1); ///< Construct MAX72xx hardware SPI driver instance for 1 device : (Chip Select pin, devices number)
54// #include <SBK_BarDrive.h>
55// SBK_BarDrive<SBK_MAX72xxHard> bar(&driver, 0, MatrixPreset::BL28_3005SK); ///< Construct using matrix type bar meter preset (auto-mapped layout) : (driver, device index, MatrixPreset type)
56
57/* === [C] Using HT16K33 via I2C === */
58#include <SBK_HT16K33.h>
59const uint8_t NUM_DEV = 1; ///< Only one device : DEV0
60const uint8_t DEV0_IDX = 0; ///< Device DEV0 index
61const uint8_t DEV0_ADD = 0x70; ///< I2C Address (typically 0x70–0x77)
62const uint8_t DEV0_NUM_ROWS = 8; ///< 20-SOP HT16K33 with only 8 rows, 24-SOP has 12 rows, 28-SOP has 16 rows
63SBK_HT16K33 driver(NUM_DEV);
64#include <SBK_BarDrive.h>
65SBK_BarDrive<SBK_HT16K33> bar(&driver, 0, MatrixPreset::BL28_3005SK); ///< Construct using matrix type bar meter preset (auto-mapped layout) : (driver, device index, MatrixPreset type)
66
67void setup()
68{
69
70#ifdef SBK_HT16K33_IS_DEFINED
71 // HT16K33 driver instance setup (demo uses a single device)
72 driver.setAddress(DEV0_IDX, DEV0_ADD); // Set I2C address for device 0
73 driver.setDriverRows(DEV0_IDX, DEV0_NUM_ROWS); // Set number of active anode outputs (rows)
74#endif
75
76 driver.begin();
77 driver.setBrightness(0, 10);
78
79 bar.setDirection(BarDirection::FORWARD);
80
81 bar.animations().animInit().fillUpIntv(50).loop();
82}
83
84void loop()
85{
86 bar.animations().update();
87 bar.show();
88}