mirror of
https://github.com/geekammo/MicroView-Arduino-Library.git
synced 2026-02-20 19:41:22 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4a45b7e6d | ||
|
|
601881997d | ||
|
|
2a7b01cfbc | ||
|
|
b35e3f2e01 | ||
|
|
66405a0972 | ||
|
|
82f3863036 |
@@ -1441,19 +1441,29 @@ void MicroViewWidget::setMaxValue(int16_t max) {
|
||||
*/
|
||||
uint8_t MicroViewWidget::getMaxValLen() { return maxValLen; }
|
||||
|
||||
/** \brief Set current value.
|
||||
/** \brief Set current value and update widget.
|
||||
|
||||
The current value of the widget is set to the variable passed in.
|
||||
The current value of the widget is set to the variable passed in and the widget is drawn with the new value.
|
||||
*/
|
||||
void MicroViewWidget::setValue(int16_t val) {
|
||||
setValue(val, true);
|
||||
}
|
||||
|
||||
/** \brief Set current value with optional update.
|
||||
|
||||
The current value of the widget is set to the variable passed in. The widget is drawn with the new value if the doDraw argument is true.
|
||||
*/
|
||||
void MicroViewWidget::setValue(int16_t val, boolean doDraw) {
|
||||
if ((val<=maxValue) && (val>=minValue)) {
|
||||
value = val;
|
||||
valLen = getInt16PrintLen(val);
|
||||
this->draw();
|
||||
if (doDraw) {
|
||||
this->draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief Get the print length of the value
|
||||
/** \brief Get the print length of the value.
|
||||
|
||||
Return the number of characters that would be printed using uView.print(value) for the current value.
|
||||
*/
|
||||
|
||||
@@ -241,6 +241,7 @@ public:
|
||||
void setMinValue(int16_t min);
|
||||
void setMaxValue(int16_t max);
|
||||
void setValue(int16_t val);
|
||||
void setValue(int16_t val, boolean doDraw);
|
||||
uint8_t getValLen();
|
||||
uint8_t getMaxValLen();
|
||||
/** \brief Draw widget value overridden by child class. */
|
||||
@@ -273,7 +274,7 @@ public:
|
||||
private:
|
||||
void drawPointer();
|
||||
uint8_t style, totalTicks;
|
||||
bool noValDraw;
|
||||
boolean noValDraw;
|
||||
int16_t prevValue;
|
||||
};
|
||||
|
||||
@@ -286,7 +287,7 @@ public:
|
||||
private:
|
||||
void drawPointer();
|
||||
uint8_t style, radius;
|
||||
bool noValDraw;
|
||||
boolean noValDraw;
|
||||
int16_t prevValue;
|
||||
};
|
||||
|
||||
|
||||
@@ -92,6 +92,9 @@ void loop() {
|
||||
</code></pre>
|
||||
|
||||
## History
|
||||
**v1.23b: 29th March 2015 by Scott Allen
|
||||
* added overloaded setValue() function to add a boolean argument doDraw which controls whether the display buffer is updated.
|
||||
|
||||
**v1.22b: 4th October 2014 by Scott Allen and Ben Lewis**
|
||||
* replaced circleFill() with a faster algorithm, better looking circle - Ben Lewis
|
||||
* replaced sprintf with dedicated code, reduced program size - Scott Allen
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
MicroView Arduino Library
|
||||
Copyright (C) 2015 GeekAmmo
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
An example of using the optional second argument of the widget
|
||||
setVal() function to update a widget without drawing the changes
|
||||
to the screen buffer.
|
||||
|
||||
This, along with the widget reDraw() function, allows widgets to be
|
||||
maintained in the "background" while other things are being displayed.
|
||||
|
||||
In this example,
|
||||
a guage and a slider are both continually updated with the same
|
||||
incrementing value. The widgets are alternately switched between the
|
||||
"background" and being displayed, at random intervals.
|
||||
*/
|
||||
|
||||
#include <MicroView.h>
|
||||
|
||||
const int highVal = 100; // high value for widget range
|
||||
|
||||
int wValue = 0; // value for widgets
|
||||
|
||||
MicroViewWidget *guage1, *slider1;
|
||||
boolean guage1On, slider1On; // true if widget is being displayed
|
||||
|
||||
void setup() {
|
||||
uView.begin();
|
||||
|
||||
guage1 = new MicroViewGauge(32, 20, 0, highVal);
|
||||
guage1On = false; // begin with guage1 off screen
|
||||
uView.clear(PAGE);
|
||||
|
||||
slider1 = new MicroViewSlider(8, 16, 0, highVal);
|
||||
slider1On = true; // begin with slider1 on screen
|
||||
|
||||
// Init the random number generator using an
|
||||
// unconnected analog pin.
|
||||
randomSeed(analogRead(A0));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Display a widget for a random number of value increments
|
||||
for (int c = random(5, 16); c > 0; c--) {
|
||||
uView.display();
|
||||
delay(500);
|
||||
|
||||
wValue++;
|
||||
if (wValue > highVal) {
|
||||
wValue = 0;
|
||||
}
|
||||
|
||||
// If the second setValue() argument is false, then
|
||||
// the display buffer is not updated.
|
||||
//
|
||||
// In a practical application, the widgets would be set with
|
||||
// the values that are being monitored.
|
||||
guage1->setValue(wValue, guage1On);
|
||||
slider1->setValue(wValue, slider1On);
|
||||
}
|
||||
|
||||
// Switch which widget is being displayed
|
||||
uView.clear(PAGE);
|
||||
|
||||
guage1On = !guage1On;
|
||||
slider1On = !slider1On;
|
||||
|
||||
if (guage1On) {
|
||||
guage1->reDraw();
|
||||
}
|
||||
|
||||
if (slider1On) {
|
||||
slider1->reDraw();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user