Seeed


A hardware innovation platform for makers to grow inspirations into differentiating products.

Potentiometer

A potentiometer is a simple knob that provides a variable resistance, which you can read into the Arch board as an analog value. In this example, you'll connect a Grove - Rotary Angle Sensor (potentiometer) to the Arch's analog Grove connector to control the rate at which the built-in LED1 blinks.

Hardware

  • Arch Board
  • Grove - Rotary Angle Sensor (potentiometer)

http://xiongyihui.github.io/archcookbook/figures/analog_world.png

Software

Import the following code to mbed online compiler

#include "mbed.h"

AnalogIn pot(P0_11);   /* Potentiometer middle pin connected to P0_11, other two ends connected to GND and 3.3V */
DigitalOut led(LED1);  /* LED blinks with a delay based on the analog input read */

int main()
{
    float ain;   /* Variable to store the analog input*/

    while(1) {
        ain = pot.read(); /* Read analog value (output will be any value between 0 and 1 */
        led = 1;          /* Switch ON LED        */
        wait(ain);        /* Wait for 'ain' Seconds (maximum delay is 1 seconds)*/
        led = 0;          /* Switch Off LED       */
        wait(ain);        /* Wait for 'ain' Seconds (maximum delay is 1 seconds)*/
    }
}

We use AnalogIn class to get the potentiometer's resistance. The pot.read() function returns a analog value. This value is used as the delay seconds for blinking.

More information of AnalogIn can be found at mbed handbook.


All wikipages