MicroView Simple Sliders with Potentiometer

kr

Introduction

MicroView can display 2 kinds of slider:

  1. The slider is positioned to the left of the readout.  This is very compact;
  2. The slider is positioned above the readout.

The sliders can be positioned anywhere on the display and both the minimum and maximum values displayed can be specified. (* note below).

A tutorial is provided to demonstrate the sliders using a potentiometer.

kr

Basic Code

#include    // include MicroView library

MicroViewWidget *widget;  // create a pointer to widget object
MicroViewWidget *widget2;  // create a pointer to widget2 object

int sensorPin = A1;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup()
{
digitalWrite(sensorPin, HIGH);                          // Internal Pull-up
pinMode(sensorPin, INPUT);                   // make pin as INPUT
uView.begin();                     // start MicroView
uView.clear(PAGE);                    // clear page
widget = new MicroViewSlider(0, 0, 0, 1024);                 // create widget object as Slider at origin, range from 0 to 1024
widget2 = new MicroViewSlider(0, 20, 0, 1024, WIDGETSTYLE1); // create widget as Slider STYLE1
uView.display();                    // display the content in the screen buffer
}

void loop()
{
sensorValue = analogRead(sensorPin);         // read sensorPin
widget->setValue(sensorValue);   // set value of sensorPin to widget
widget2->setValue(sensorValue);   // set value of sensorPin to widget
uView.display();           // display the content in the screen buffer
}

Notes

  1. The value stored from the sensor ranges from 0 to 1024 (at 5V).  The range of the slider merely ‘zooms in’ on part of this.  In other words, if the slider minimum is set to (say) 300, that does NOT then correspond to 0V on the input.  It simply means any value below 300 falls off the left hand slide of the slider – the slider continues to show 300 as this is the minimum it is allowed to display.
  2. The sliders appear to be fixed width.  Setting the x coordinate too high can push the slider off the rhs of the screen, or cause it to wrap around.

This image shows the effect of changing the min/max display range, with the first widget ‘maxed out’ at 600 and the second showing the true value of 677 (out of 1024).  Also, the x co-ords have been set to 40 to push the sliders off the screen, as in the following code snippet:

widget = new MicroViewSlider(40, 0, 300, 600);
widget2 = new MicroViewSlider(40, 20, 0, 1024, WIDGETSTYLE1);

kr

Summary

The two sliders are well thought out and provide a great deal of information for the real estate they take up on the screen.  The quality of the OLED display is really makes these viable – great!

NB:  All code modified from MicroView Learning Kit supplied by Geek Ammo.  Cheers!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s