//////////////////////////////////////////////////////////////////////////////
/// @file main.cpp
/// @author Kai R.
/// @brief Simple demonstration of a button class.
///
/// @date 2022-05-20
/// @version 1.0
///
/// @copyright Copyright (c) 2022
///
//////////////////////////////////////////////////////////////////////////////
#include <Arduino.h>
#include "Button.hpp"
#include "Wrapper.hpp"
//////////////////////////////////////////////////
// Definitions
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// Global constants and variables
//////////////////////////////////////////////////
constexpr uint8_t BUTTON_PIN1 {6};
constexpr uint8_t BUTTON_PIN2 {7};
//Button bArray[] { Button{BUTTON_PIN1}, Button{BUTTON_PIN2} };
ButtonControl bControl{8,7,6};
RotaryEncoderControl recControl{11,10,9};
//////////////////////////////////////////////////
// Function forward declaration
//////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// @brief Initialize the program.
///
//////////////////////////////////////////////////////////////////////////////
void setup () {
Serial.begin(115200);
bControl.begin();
recControl.begin();
}
//////////////////////////////////////////////////////////////////////////////
/// @brief Time display and time synchronization.
///
//////////////////////////////////////////////////////////////////////////////
void loop () {
switch(bControl.control()) {
case Position::left: Serial.println(F("Links")); break;
case Position::middle: Serial.println(F("Mitte")); break;
case Position::right: Serial.println(F("Rechts")); break;
}
switch(recControl.control()) {
case Position::left: Serial.println(F("Links")); break;
case Position::middle: Serial.println(F("Mitte")); break;
case Position::right: Serial.println(F("Rechts")); break;
}
}
/*
// -----
// SimplePollRotator.ino - Example for the RotaryEncoder library.
// This class is implemented for use with the Arduino environment.
//
// Copyright (c) by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD 3-Clause License. See http://www.mathertel.de/License.aspx
// More information on: http://www.mathertel.de/Arduino
// -----
// 18.01.2014 created by Matthias Hertel
// 04.02.2021 conditions and settings added for ESP8266
// -----
// This example checks the state of the rotary encoder in the loop() function.
// The current position and direction is printed on output when changed.
// Hardware setup:
// Attach a rotary encoder with output pins to
// * A2 and A3 on Arduino UNO.
// * D5 and D6 on ESP8266 board (e.g. NodeMCU).
// Swap the pins when direction is detected wrong.
// The common contact should be attached to ground.
#include <Arduino.h>
#include <RotaryEncoder.h>
// Example for Arduino UNO with input signals on pin 2 and 3
#define PIN_IN1 9
#define PIN_IN2 11
// Setup a RotaryEncoder with 4 steps per latch for the 2 signal input pins:
// RotaryEncoder encoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::FOUR3);
// Setup a RotaryEncoder with 2 steps per latch for the 2 signal input pins:
RotaryEncoder encoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::TWO03);
void setup()
{
Serial.begin(115200);
while (! Serial);
Serial.println("SimplePollRotator example for the RotaryEncoder library.");
} // setup()
// Read the current position of the encoder and print out when changed.
void loop()
{
static int pos = 0;
encoder.tick();
int newPos = encoder.getPosition();
if (pos != newPos) {
Serial.print("pos:");
Serial.print(newPos);
Serial.print(" dir:");
Serial.println((int)(encoder.getDirection()));
pos = newPos;
} // if
} // loop ()
// The End
*/