To read the value from the analog input, we will use the good 'ole Arduino library function analogRead(). You can use the sketch below to read the value from the potentiometer (attached to #10) and print it on the serial output.
/////////////////////////////////////////////////////////////////////////////// // Circuit Playground Analog In - Serial Print // // Author: Carter Nelson // MIT License (https://opensource.org/licenses/MIT) #include <Adafruit_CircuitPlayground.h> uint16_t value; /////////////////////////////////////////////////////////////////////////////// void setup() { Serial.begin(9600); CircuitPlayground.begin(); } /////////////////////////////////////////////////////////////////////////////// void loop() { value = analogRead(10); Serial.println(value); delay(100); }
With this sketch running on the Circuit Playground, open the Serial Monitor:
Tools -> Serial Monitor
You should see the value being printed out. Now try spinning the knob and you should see the value change.
If you turn the knob all the way in one direction, you should get a value of 0. If you turn the knob all the way in the other direction, you should get a value of 1023. This is the range of values provided by the 10 bit analog to digital converter.
You can also use the Serial Plotter to watch the value change.
Tools -> Serial Plotter
Now try turning the knob and watch the line go up and down. Wheeeee!!!!
Page last edited February 08, 2017
Text editor powered by tinymce.