RGB-энкодер (Troyka-модуль)
Примеры работы
Тест кнопки и цвета
- troyka-encoder-rgb-color-setter.ino
// Include library #include "RGBEncoder.h" // Create an RGBEncoder object RGBEncoder knob; int i = 0; // Handler of button void buttonHandler(bool pressed) { if (!pressed) return; if (i == 0) { knob.setColor(255, 0, 0); i++; } else if (i == 1) { knob.setColor(0, 255, 0); i++; } else if (i == 2) { knob.setColor(0, 0, 255); i++; } else if (i == 3) { knob.setColor(0, 0, 0); i = 0; } } void setup() { knob.begin(); // initialize // register handlers for button and encoder knob.onButton(buttonHandler); // switch-off led knob.setColor(0, 0, 0); } void loop() { knob.update(); // upkeep to trigger the handler when necessary }
Тест поворота
- troyka-encoder-rgb-simple-rotate.ino
/* * This example demonstrates the use of RGBEncoder to control a stepper motor. */ // Include library #include "RGBEncoder.h" int i = 0; // Create object of RGBEncoder RGBEncoder knob; // Handler. Called when the encoder is turned left void stepLeft() { Serial.println(knob.getEncoderValue()); } // Handler. Called when the encoder is turned right void stepRight() { Serial.println(knob.getEncoderValue()); } void setup() { Serial.begin(9600); knob.begin(); // initialisation //knob.setStep(1); knob.setRange(-100, 100); // Register on-step handlers knob.onStepLeft(stepLeft); knob.onStepRight(stepRight); } void loop() { knob.update(); // upkeep to trigger the handler when necessary }