Internet of Things
TinkerforgeCode in ActionAbout Me
  • Course Outline
  • 1 - Getting Started
    • Overview
    • Connect to the LED
    • Getting Started
      • Glitch
      • The Application Template
    • Concepts in Programming
      • What is Programming?
      • Variables
      • Functions and Commands
      • Control Structures
      • Loops
      • Objects and Libraries
    • Programming Simple Web Apps
    • Exercises
      • 1.1 Buttons and Inputs
  • 2 - Internet of Things
    • Overview
    • IoT in our Apps
      • Getting Started
        • Hardware Kit
        • Brick Viewer and Daemon
      • Connect to the Devices
        • The Tinkerforge Device Manager
      • Program the Devices
        • RGB LED
        • RGB LED Button
        • OLED Display
        • Sensors
          • Humidity Sensor
          • Ambient Light Sensor
    • Components and Use Cases
    • Exercises
      • 2.1 Lights and Buttons
      • 2.2 Sensors
      • 2.3 Display
  • 3 - Artificial Intelligence
    • Overview
    • AI in our Apps
      • Google's Teachable Machine
      • Face Recognition
      • Training a Custom Model
    • Rules vs. Learning
    • Learning from Data
    • Use Cases
      • Computer Vision
        • Image Classification
        • Handwriting Recognition
    • Machine Learning Algorithms
      • Artificial Neural Networks
      • Decision Trees
      • Logistic Regression
    • Exercises
      • 3.1 Rules vs. Learning
      • 3.2 Fruits and Vegetables
      • 3.3 Face Recognition
      • 3.4 A Classifier for Iris
  • 4 - Cloud & APIs
    • Overview
    • APIs in our Apps
    • Cloud and APIs
      • Weather API
      • NASA Open APIs
      • EDAMAM Nutrition and Recipes API
    • Push Notifications
    • Exercises
  • 5 - App Project
    • Overview
    • Summer 2021
    • Summer 2022
  • Appendix
    • Other Devices
      • Motorized Linear Poti
      • Sound Pressure Sensor
      • NFC Reader
      • Motion Detector
    • UI Features
      • Realtime Charts
      • Countdown Timer
    • Digital Computers
      • Overview
      • The Binary System
      • Code Systems
      • Logic Gates
      • Binary Addition
      • From Analog to Digital
    • Cheat Sheets
    • Projects
      • IoT @ Pickup-Boxes
Powered by GitBook
On this page
  • Get the updates about the position
  • Set the position using the motor

Was this helpful?

  1. Appendix
  2. Other Devices

Motorized Linear Poti

PreviousOther DevicesNextSound Pressure Sensor

Last updated 4 years ago

Was this helpful?

We can use the to let the user control some aspect of our application using a physical control. The poti can take on values on a range between 0 and 100.

Using the , we can use simple functions to perform the most important tasks. In this article, we assume you have successfully initialized the devices with the , and you stored all connected devices on a global variable devices. We also declared a global variable poti.

Next, we need to know the device identifier of the Motorized Linear Poti, which is 267:

// Get a reference to the poti device and store in on the global variable
poti = devices.getDeviceByIdentifier(267);

Now that we have a reference to the display on the variable poti, we can use that variable to call the device's functions.

Get the updates about the position

In a sense, the Motorized Linear Poti acts like a sensor: We can register a listener to get updates about changes to its position. We first register the listener:

poti.registerListener(potiChanged);

In the callback function, we can distinguish between two types of updates from the device:


function potiChanged(val) {

    // Get the value
    var value = val.getValue():
    
    if(value.type == "position") {
        // Do something
    }
    else if (value.type == "position_reached") {
        // Do something else
    }
}

If we are only interested in the position of the poti, regardless of whether it was changed manually or with the motor, we can use the event type position. If we are using the motor, as described below, and we want to know when the motor is done moving the slider, we can use the event type position_reached. This event is only fired when the motor was used, and it has finished the move.

Note that you'll get each position changed using the motor also via the event position.

Set the position using the motor

A nice feature of the Motorized Liner Poti is that it has a motor that lets us set the value programmatically:

// Set the poti to position 75 using the integrated motor
poti.setPosition(75);

The motor moves the slider, which will take a couple of milliseconds. If we want to know when the motor is done, we can check for the "position_reached" event, as described above.

Motorized Linear Poti
Tinkerforge Device Manager
Tinkerforge Device Manager