Encoder example

The encoder sensor device has to be connected to the sensor module. Encoder sensor device has a two 3,5 mm plugs what has to be connected to the sensor module 3,5 mm input jackets. The controller and sensor modules must be connected.

The jackets must be inserted to the right input. Four channel input to D jacket (right) and three channel input to the A jacket(left).

Needed libraries

lib_deps = ITTIoT, Encoder

The example code will print out encoder current position value

#include <Arduino.h>
#include <ittiot.h>
#include <Ticker.h>
#include <Encoder.h>
#define ENC_PIN_1 12
#define ENC_PIN_2 13
Encoder myEnc(ENC_PIN_1, ENC_PIN_2);
Ticker encTicker;
long oldPosition  = -999;
bool encFlag;
void iot_connected()
  Serial.println("MQTT connected callback");
  iot.log("IoT encoder example!");
void setEncFlag()
void setup()
  iot.printConfig(); // print json config to serial //Peale Serial.begin ja enne iot.setup
  encTicker.attach(1, setEncFlag);
void loop()
  // Send encoder reading to the serial port, when it changes
  long newPosition = myEnc.read();
  if (newPosition != oldPosition)
    oldPosition = newPosition;
    Serial.print("Encoder: ");
  // Send encoder reading to server
      encFlag = false;
      String msg = String(newPosition);
      iot.publishMsg("enc", msg.c_str());
en/iot/examples/encoder.txt · Last modified: 2018/12/27 12:53 (external edit)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0