#include <adafruit_1947.h> // Screen lib.
#include <eventMgr.h> // Interaction manager.
#include <label.h> // A display.
#include "sliderPuzzle.h" // Game logic.
#define DSP_CS 10 // Display chip select
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.
if (setupSD()) { // Got SD as well?
setupScreen(); // Populate the screen.
return; // Everything fired up successfuly. Lets go!
} //
} //
} else { // Else the display didn't.
Serial.println("NO SCREEN!"); // Send an error out the serial port.
} //
Serial.println("Locking process."); // Tell 'em
while(true)delay(10); // Lock processor here forever.
}
bool setupSD(void) {
if (SD.begin(SD_CS)) { // If it works..
return true;
}
Serial.println("NO SD CARD!"); // Send an error out the serial port.
return false;
}
// 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.
} //
}
/*
#include <adafruit_1947.h>
#include <colorObj.h>
#include <idlers.h>
#include <lists.h>
#include <mapper.h>
#include <drawObj.h>
#include <lilOS.h>
#include "handheldOS.h"
#define DSP_CS 10
#define SD_CS 4
void bootError(const char* errStr) {
screen->fillScreen(&black); // Fill the screen black.
screen->setCursor(10,10); // Move cursor to the top left.
screen->setTextColor(&white); // Drawing in white..
screen->setTextSize(2); // Big enought to notice.
screen->drawText(errStr); // Draw the error message.
analogWrite(SCREEN_PIN,255); // Bring up the screen.
while(1); // Lock down.
}
// Setup, get the hardware running then fire up the UI & OS.
void setup() {
bool haveScreen;
Serial.begin(9600);
haveScreen = false;
analogWrite(SCREEN_PIN,0); // Turn off backlight.
screen = (displayObj*) new adafruit_1947(DSP_CS,-1);
//screen = (displayObj*) new teensy_1947(DSP_CS,-1);
if (screen) {
if (screen->begin()) {
screen->setRotation(PORTRAIT);
haveScreen = true;
}
}
if (!haveScreen) {
Serial.println("NO SCREEN!"); // Send an error out the serial port.
Serial.flush(); // Make sure it goes out!
while(true); // Lock processor here forever.
}
if (!SD.begin(SD_CS)) { // With icons, we now MUST have an SD card.
Serial.println("NO SD CARD!"); // Send an error out the serial port.
Serial.flush(); // Make sure it goes out!
bootError("No SD card."); // Since we have a display, display the error.
analogWrite(SCREEN_PIN,255); // Turn on backlight.
}
// If we get here, looks like we have hardware running.
ourEventMgr.begin(); // Kickstart our event manager.
ourOS.begin(); // Fire up our OS sevices.
//nextPanel = navTestApp;
}
// During loop..
void loop() {
idle(); // Idlers get their time.
ourOS.loop(); // ourOS gets a kick to pass on to the current panel.
}
Loading
ili9341-cap-touch
ili9341-cap-touch