I will be maintaining my libraries here:
http://bit.ly/pATDBi

I am the lead developer for libraries 
that ship with the Wiring distribution. 
As per version 1.0 -
Wiring will support Arduino boards.
You are welcome to check it out!
http://wiring.org.co/download/
Potentiometer Library for Arduino
Author:  Alexander Brevig
Contact: alexanderbrevig@gmail.com


Navigation


Current version

1.2.1 2011-12-11 - TVHeadedRobots: Modified includes to add Arduino 1.0 compatibility


History

1.1 2009-04-07: Altered API
1.0 2008-10-23: Initial Release


Description

Potentiometer is a library for the Arduino.

It is created to help Hardware Abstraction, and readability of code.

It hides the pinMode, and digitalRead calls for the user.

Potentiometer library is part of the Hardware Abstraction libraries.


Download, install and import

Download here: Attach:Potentiometer.1.2.1.zip

Put the Potentiometer folder in "hardware\libraries\".

In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library->Potentiometer".

Once the library is imported, an "#include <Potentiometer.h>" line will appear at the top of your Sketch.


Creation

Potentiometer(byte potPin) Potentiometer(byte potPin, uint sectors)

Potentiometer potentiometer = Potentiometer(2);

Instanciates a Potentiometer object at analog pin number (2).


Functions

uint getState()

Returns the current state of the Potentiometer. true == on()

uint getValue()

Returns the results of analogRead(pin)

uint getSector()

Returns the current sector of which the potentiometer is at that instance

void setSectors(uint sectors)

Set the number of sectors for the potentiometer


Example

#include <Potentiometer.h>

Potentiometer potentiometer = Potentiometer(2); //a Potentiometer at analog in 2

void setup(){
  Serial.begin(9800);
  Serial.println("Potentiometer example");
  delay(2000);
}

void loop(){
  Serial.print("potentiometer.getValue() ");
  Serial.println(potentiometer.getValue(),DEC);
  Serial.print("potentiometer.getSector() ");
  Serial.println(potentiometer.getSector(),DEC);
  Serial.println();
  delay(1000);
}


FAQ

How can I use multiple Potentiometers?

Potentiometer is a class. Therefore to Potentiometer multiple digital pins, you must create an instance for each of them. In the example above, a Potentiometer instance (Potentiometer Potentiometer) for analog pin 2 is created with the following line:

Potentiometer potentiometer = Potentiometer(2);

To add a Potentiometer to an additional pin (pin 4 for example), you could create the following instance calPotentiometer potentiometer2:

Potentiometer potentiometer2 = Potentiometer(4);

And now it's just to call the functions you need on the Potentiometer you are interested in:

//get potentiometer states
  uint val = potentiometer.getValue();
  uint sector = potentiometer2.getSector();


Information about this page

Part of AlphaBeta Libraries.
Last Modified: December 11, 2011, at 05:36 PM
By: tvheadedrobots

Share