#include <adafruit_1947.h> // Screen lib.
#include <eventMgr.h> // Interaction manager.
#include <label.h> // A display.
#include <slider.h> // The slider class we're showing off today.
#define DSP_CS 10 // Display chip select
slider* aSlider; // The slider to slide about.
label* alabel;
colorObj backColor; // We setup a colorObj for the backGndRect color of the display.
int sliderValue;
// The way setup() works here is mostly for hardware setup. If that all works?
// Then we go on to setup the srceen object and controls.
void setup() {
Serial.begin(115200);
Serial.println("Sliders");
screen = (displayObj*) new adafruit_1947(DSP_CS,-1); // Create our screen object.
if (screen) { // We got one? Cool!
if (screen->begin()) { // Can we successfully call begin on the screen?
screen->setRotation(PORTRAIT); // Ok, set portrait. Good for handhelds.
ourEventMgr.begin(); // We are looking for touch sceen action! Fire up the even manager.
setupScreen(); // Populate the screen.
return; // Everything fired up successfuly. Lets go!
} //
} //
Serial.println("NO SCREEN!"); // Send an error out the serial port.
while(true)delay(10); // Lock processor here forever.
}
// Extension to setup() that puts all the scren bits and things together.
void setupScreen(void) {
// Setup backGndRect display color.
backColor.setColor(&blue); // Set this color object to blue.
backColor.blend(&white,70); // Lets lighten it, mixin some white.
screen->fillScreen(&backColor); // A command to "screen" happens (NOW). Objects update later.
//aSlider = new slider(20,40,20,120,true); // Create a vertical slider object. <<<=== Choose one
aSlider = new slider(20,40,120,20,false); // Create a horizontal slider object. <<<=== or the other.
alabel = new label(60,70,150,16); // Create a label.
if (aSlider&&alabel) { // If we got one..
aSlider->setColors(&blue,&backColor); // Set it's color pallette. KNob color, background color.
alabel->setColors(&blue,&backColor); // Make a label.
viewList.addObj(aSlider); // Add the slider (It's a pointer) to the view list to be managed.
viewList.addObj(alabel); // And the label (It's also a pointer) to the view list to be managed.
sliderValue = -1; // -1 flags as a value it can't attain.
} else { // Didn't get a slider?
Serial.println("No slider!"); // Tell Miss user.
while(true)delay(10); // Lock processor here forever.
} //
}
// In loop, make a call to idle.
void loop() {
float newValue;
int newIntValue;
idle(); // Runs all the mnagic.
newValue = aSlider->getValue(); // Read the slider value.
newIntValue = round(newValue); // Round it to an integer.
if (sliderValue!=newIntValue) { // If not the same as the saved value..
alabel->setValue(newIntValue); // Show the new value.
sliderValue = newIntValue; // Up date the saved value to the new value.
} //
}