#include <adafruit_1947.h>
#include <colorBargraph.h>
#include <autoPOT.h>
#include <mapper.h>
#define DSP_CS 10 // Display chip select
colorBargraph* ourBargraph; // A rectangle object that is a solid color. Top to Bottom
colorBargraph* ourBargraph2; // A rectangle object that is a solid color. Bottom to Top.
colorBargraph* ourBargraph3; // A rectangle object that is a solid color. Left to right.
colorBargraph* ourBargraph4; // A rectangle object that is a solid color. Right to left.
colorObj backColor; // We setup a colorObj for the backGndRect color of the display.
autoPOT valueControl(A0); // Auto POT watches an analog pin and when a value changes, it reports it.
mapper RPMMapper(0,1023,0,10000); // A mapper to map raw POT values to an pretend RPM..
// 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("Tach. bargraphs..");
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.
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.
}
// When the POT sees a change in value. The new value arrives here.
void RPMChange(int newValue) {
float RPM;
RPM = RPMMapper.map(newValue);
ourBargraph->setValue(RPM);
ourBargraph2->setValue(RPM);
ourBargraph3->setValue(RPM);
ourBargraph4->setValue(RPM);
Serial.print("RPM : ");
Serial.println(RPM);
}
// Extension to setup() that puts all the scren bits and things together.
void setupScreen(void) {
rect locator(20,40,20,150);
// Setup backGndRect display color.
backColor.setColor(&blue); // Set this color object to blue.
backColor.blend(&black,70); // Lets darken it, mixin some black.
screen->fillScreen(&backColor); // A command to "screen" happens (NOW). Objects update later.
// Setup a bargraphs we can change the value of.
valueControl.setCallback(RPMChange); // Setup the callback for the POT.
ourBargraph = new colorBargraph(&locator,&black); // Create our colorBargraph object.
locator.insetRect(-1); // Expand the locater by 1 pixel all around.
screen->drawRect(&locator,&white); // Use this to draw a white frame around the bar graph.
locator.insetRect(1); // Inset the rect back to what it was originally.
if (ourBargraph) { // If we got one..
ourBargraph->addColor(0,&black); // Start putting int the value,color data points.
ourBargraph->addColor(800,&green); //
ourBargraph->addColor(6000,&green); //
ourBargraph->addColor(6500,&yellow); //
ourBargraph->addColor(7500,&yellow); //
ourBargraph->addColor(8500,&red); //
ourBargraph->addColor(10000,&red); //
viewList.addObj(ourBargraph); // Add the object (It's a pointer) to view list to be managed.
ourBargraph->setValue(0); // Start it at zero.
} else { // Didn't get a rect?
Serial.println("No color Bargraph!"); // Tell Miss user.
while(true)delay(10); // Lock processor here forever.
} //
locator.x = locator.x + 40; // Move the locater rect over a bit.
ourBargraph2 = new colorBargraph(&locator,&black,topDown); // Create our colorBargraph object. But top down.
locator.insetRect(-1); // Do the stuff for the white border.
screen->drawRect(&locator,&white); // draw it.
locator.insetRect(1); // Put the rect back to size.
if (ourBargraph2) { // Setup and drop it into the viewList.
ourBargraph2->addColor(0,&black);
ourBargraph2->addColor(800,&green);
ourBargraph2->addColor(6000,&green);
ourBargraph2->addColor(6500,&yellow);
ourBargraph2->addColor(7500,&yellow);
ourBargraph2->addColor(8500,&red);
ourBargraph2->addColor(10000,&red);
viewList.addObj(ourBargraph2);
ourBargraph2->setValue(0);
} else {
Serial.println("No color Bargraph!");
while(true)delay(10);
}
locator.setRect(20,210,150,20);
ourBargraph3 = new colorBargraph(&locator,&black,leftRight); // Do the next one left to right.
locator.insetRect(-1);
screen->drawRect(&locator,&white);
locator.insetRect(1);
if (ourBargraph3) {
ourBargraph3->addColor(0,&black);
ourBargraph3->addColor(800,&green);
ourBargraph3->addColor(6000,&green);
ourBargraph3->addColor(6500,&yellow);
ourBargraph3->addColor(7500,&yellow);
ourBargraph3->addColor(8500,&red);
ourBargraph3->addColor(10000,&red);
viewList.addObj(ourBargraph3);
ourBargraph3->setValue(0);
} else {
Serial.println("No color Bargraph!");
while(true)delay(10);
}
locator.y = locator.y + 40;
ourBargraph4 = new colorBargraph(&locator,&black,rightLeft); // And the last one right to left.
locator.insetRect(-1);
screen->drawRect(&locator,&white);
locator.insetRect(1);
if (ourBargraph4) {
ourBargraph4->addColor(0,&black);
ourBargraph4->addColor(800,&green);
ourBargraph4->addColor(6000,&green);
ourBargraph4->addColor(6500,&yellow);
ourBargraph4->addColor(7500,&yellow);
ourBargraph4->addColor(8500,&red);
ourBargraph4->addColor(10000,&red);
viewList.addObj(ourBargraph4);
ourBargraph4->setValue(0);
} else {
Serial.println("No color Bargraph!");
while(true)delay(10);
}
}
// In loop call to idle to run all the mnagic.
void loop() { idle(); }