I will be maintaining my libraries here: https://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! https://wiring.org.co/download/
Potentiometer Library for Arduino Author: Alexander Brevig Contact: alexanderbrevig@gmail.com
1.2.1 2011-12-11 - TVHeadedRobots: Modified includes to add Arduino 1.0 compatibility
1.1 2009-04-07: Altered API
1.0 2008-10-23: Initial Release
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 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.
Potentiometer(byte potPin) Potentiometer(byte potPin, uint sectors)
Potentiometer potentiometer = Potentiometer(2);
Instanciates a Potentiometer object at analog pin number (2).
Returns the current state of the Potentiometer. true == on()
Returns the results of analogRead(pin)
Returns the current sector of which the potentiometer is at that instance
Set the number of sectors for the potentiometer
#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); }
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();
Part of AlphaBeta Libraries. | |
Last Modified: | December 11, 2011, at 05:36 PM |
By: | tvheadedrobots |